Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Inventory Management Etc.
Index -> Programming, PHP -> PHP Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rdrake




PostPosted: 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
Sponsor
sponsor
Velandil




PostPosted: 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




PostPosted: 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.
code:
$fields = array("id", "d", "t", "l", "h", "v", "type");

        // 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>";
        }
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 18 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: