I am somewhat new to PHP and am running into an issue. Here is what I have:
$select_all = "SELECT * FROM latesttest";
$result = mysql_query($select_all)
or die(mysql_error());
$row = mysql_fetch_assoc($result);
foreach($row as $k=>$v){
echo $k . "=" . $v . "<br />";
}
This works and gives me: V1=Test V2=1234 V3=Something etc.
But I want to have the results for each row in the table reflected in this way. If I run the SELECT * FROM latesttest; in MySQL, I have 4 records in this table. How do I show all 4 rows in this above format?
while ($row = mysql_fetch_assoc($result)) {
foreach($row as $k=>$v){
echo $k . "=" . $v . "<br />";
}
}
Ta-da!
fetch_assoc() only returns a SINGLE result row as an array, so your for() loop is just iterating over the fields in that one row. The code should be
while($row = mysql_fetch_assoc($result)) {
foreach ($row as $key => $val) {
echo "$key => $val<br />";
}
}