Posted: Wed Nov 09, 2005 3:48 pm Post subject: (No subject)
I might have forgotten some code there.
code:
<?
$q = "SELECT * FROM inventory WHERE list=\"name\"";
$r = mysql_query($q);
if($r == 0) die("<p><strong>0</strong> results found.</p>");
while ($row = mysql_fetch_assoc($r)) {
echo "<option>".$row["inventory_company"]."</option>";
}
?>
The variable row contains every entry in that row of the table, in the form of an array. Just change the value inside the square brackets to whatever field you want to populate the select box with.
For some reason I forgot that, probably too early for thinking when I wrote it. That new code should work.
If you keep getting the message "0 results returned" and your table does have some rows in it, then try just removing that line to see if it works.
Sponsor Sponsor
Velandil
Posted: Thu Nov 10, 2005 11:37 pm Post subject: (No subject)
If I remove that line, I get:
code:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\netit\test.php on line 14
Any idea?
rdrake
Posted: Fri Nov 11, 2005 7:26 am Post subject: (No subject)
The following is an example of this type of thing in action. I made it for a scheduling application, but I'm sure you could play around with the code and make it work with your app too. I don't know what's wrong with the code, provided you used the most recent code I gave you.
// Find all games for that team
$q = "SELECT * FROM $div WHERE h = \"$team\" OR v = \"$team\"";
$r = mysql_query($q);
if($r == 0) die("<p><strong>0</strong> results found.</p>");
while ($row = mysql_fetch_assoc($r)) {
foreach($fields as $value) {
echo $row[$value];
}
echo "</tr>";
}