Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql query and php arrays

Status
Not open for further replies.

roycrom

Programmer
Aug 2, 2002
184
GB
Hi I am trying to display a web page. I have a database table with 11 fields. I have populated a php array with the field headers
Code:
$FIELDS=array("Barcode", "Status"......);
$result=mysql_query("SELECT * FROM table WHERE Barcode=$Barcode");  //barcode from $_GET variable
$row=mysql_fetch_row($result); //only 1 row will return
Now I want to use the echo to print put each valuein the returned row array, such as
Code:
foreach($FIELDS as $VARIABLE) {
    echo "$VARIABLE<BR>";  //Make sure var is set
    echo "$row[$VARIABLE]<BR>";  //This line just blank
}
So variable is printing out, but I am just getting blank lines for $row[$VARIABLE]. Is it not possible to pull result back from a $row array like this? Anytips on a better way?

Thanks for any help you can give.

------------------------------------------
Somethings come from nothing, nothing seems to come from somethings - SFA - Guerilla

roycrom :)
 
i think you might need to change your foreach loop

Code:
foreach($row as $val):
    echo "$val <BR/>";
endforeach;

and if you want the field names

Code:
$row=mysql_fetch_assoc($result); //only 1 row will return
echo "<table>";
foreach ($row as $key=>$val):
 echo "<tr><td>$key</td><td>$val</td></tr>";
endforeach;
echo "</table>";

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top