Here's one for you 😃
I'm trying to populate a prebuilt table based
webpage with data from a mysql table.
What I want to do is assign each field in
one row of a table it's own variable.
For example:
The table has customer data like first name,
last name etc.
I'd like their value to be assigned to a $fname
$lname etc etc
I've been banging my head against my keyboard
for a while now and have come up with the
following but I bet there is a better way to do this.
Any ideas?
<?php
/*/// Connect And Report ///*/
mysql_connect("localhost", "melvin", "42password42")or die("Could not connect: " . mysql_error());
mysql_select_db("menagerie") or die("Could Not Select Database");
$order = $_POST["order"];
$ord = "SELECT onum FROM otab";
$fn = "SELECT fname FROM customers;";
$ln = "SELECT lname FROM customers;";
$ad = "SELECT address FROM customers;";
$ci = "SELECT city FROM customers;";
$st = "SELECT state FROM customers;";
$zi = "SELECT zip FROM customers;";
//
$field = mysql_query($fn) or die("Query Failed: " . mysql_error());
WHILE ($line = mysql_fetch_array($field, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
$fname = $col_value; }
}
//
// Instead of writing one of these for each variable
// does anyone know of a way to assign each field it's own variable?
//
$field = mysql_query($ln) or die("Query Failed: " . mysql_error());
WHILE ($line = mysql_fetch_array($field, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
$lname = $col_value; }
}
?>
Thank You In Advance 🙂