mysqli - PHP - First query works, but the others don't -
this question has answer here:
first of all, variables , text german, i, hope not problem. so, first question, first query works fine. dont know why others don't work, guess because of multiple querys!
i new programming.
this php update database of paletts!
<?php // sql login $host = "localhost"; $user = "name"; $password = "password"; $db = "test_nico"; $mysqli = new mysqli($host, $user, $password, $db) or die (mysqli_error()); if (!$mysqli) { echo 'sql server nicht gefunden oder zugangsdaten passen nicht!';}; $mysqli->query("set names 'utf8'"); if ($mysqli->connect_errno) { die("verbindung fehlgeschlagen: " . $mysqli->connect_error); } // tauschpartner id $id = $_post['id']; // eingang $eingang_pgp = $_post['eingang_pgp']; $eingang_pfp = $_post['eingang_pfp']; $eingang_klt = $_post['eingang_klt']; $eingang_halbe = $_post['eingang_halbe']; $eingang_viertel = $_post['eingang_viertel']; // ausgang $ausgang_pgp = $_post['ausgang_pgp']; $ausgang_pfp = $_post['ausgang_pfp']; $ausgang_klt = $_post['ausgang_klt']; $ausgang_halbe = $_post['ausgang_halbe']; $ausgang_viertel = $_post['ausgang_viertel']; // query $search = "select * tauschpartner"; $result = mysqli_query($mysqli, $search); while($row = mysqli_fetch_array($result)) { $tid = $row['id']; $firma_array[$tid] = $row['firma']; $pfp_array[$tid] = $row['pfp']; $pgp_array[$tid] = $row['pgp']; $klt_array[$tid] = $row['klt']; $halbe_array[$tid] = $row['halbe']; $viertel_array[$tid] = $row['viertel']; } // bestand $pgp_bestand = $pgp_array[$id]; $pfp_bestand = $pfp_array[$id]; $klt_bestand = $klt_array[$id]; $halbe_bestand = $halbe_array[$id]; $viertel_bestand = $viertel_array[$id]; // berechnung $pgp = $pgp_bestand + $eingang_pgp - $ausgang_pgp; $pfp = $pfp_bestand + $eingang_pfp - $ausgang_pfp; $klt = $klt_bestand + $eingang_klt - $ausgang_klt; $halbe = $halbe_bestand + $eingang_halbe - $ausgang_halbe; $viertel = $viertel_bestand + $eingang_viertel - $ausgang_viertel; // sql query $sql_query = "update tauschpartner set pfp = $pfp, pgp = $pgp, klt = $klt, halbe = $halbe, viertel = $viertel id = $id"; $sql = mysqli_query($mysqli, $sql_query); echo "id: ".$id."\n"; echo "eingang_pgp: ".$eingang_pgp."\n"; echo "eingang_pfp: ".$eingang_pfp."\n"; echo "eingang_klt: ".$eingang_klt."\n"; echo "eingang_halbe: ".$eingang_halbe."\n"; echo "eingang_viertel: ".$eingang_viertel."\n"; echo "\n"; echo "ausgang_pgp: ".$ausgang_pgp."\n"; echo "ausgang_pfp: ".$ausgang_pfp."\n"; echo "ausgang_klt: ".$ausgang_klt."\n"; echo "ausgang_halbe: ".$ausgang_halbe."\n"; echo "ausgang_viertel: ".$ausgang_viertel."\n"; echo "\n"; echo "bestand pgp: ".$pgp."\n"; echo "bestand pfp: ".$pfp."\n"; echo "bestand klt: ".$klt."\n"; echo "bestand halbe: ".$halbe."\n"; echo "bestand viertel: ".$viertel."\n"; echo "\n"; $sql_query_all = "select sum(pgp) pgp_all, sum(pfp) pfp_all, sum(klt) klt_all, sum(halbe) halbe_all, sum(viertel) viertel_all tauschpartner id != 1"; $sql = mysqli_query($mysqli, $sql_query_all); while($row_all = mysqli_fetch_array($sql)) { $pgp_bestand_all = $row['pgp_all']; $pfp_bestand_all = $row['pfp_all']; $klt_bestand_all = $row['klt_all']; $halbe_bestand_all = $row['halbe_all']; $viertel_bestand_all = $row['viertel_all']; }; $sql_query_update_gd_bestand = "insert tauschpartner set pgp = $pgp_bestand_all, pfp = $pfp_bestand_all, klt = $klt_bestand, halbe = $halbe_bestand_all, viertel = $viertel_bestand_all id =1"; $sql = mysqli_query($mysqli, $sql_query_update_gd_bestand); echo $row['viertel_all']."\n"; echo "gd bestand pgp: ".$pgp_bestand_all."\n"; echo "gd bestand pfp: ".$pfp_bestand_all."\n"; echo "gd bestand klt: ".$klt_bestand_all."\n"; echo "gd bestand halbe: ".$halbe_bestand_all."\n"; echo "gd bestand viertel: ".$viertel_bestand_all; echo "\n"; ?> can tell me why queries aren't working?
thanks in advance, nico
in below code while loop using $row_all when fetching value using $row. change it, work.
$sql_query_all = "select sum(pgp) pgp_all, sum(pfp) pfp_all, sum(klt) klt_all, sum(halbe) halbe_all, sum(viertel) viertel_all tauschpartner id != 1"; $sql = mysqli_query($mysqli, $sql_query_all); while($row_all = mysqli_fetch_array($sql)) { // see here $pgp_bestand_all = $row_all['pgp_all']; // change $row $row_all $pfp_bestand_all = $row_all['pfp_all']; $klt_bestand_all = $row_all['klt_all']; $halbe_bestand_all = $row_all['halbe_all']; $viertel_bestand_all = $row_all['viertel_all']; }; i hope resolve problem.
Comments
Post a Comment