phpBegginer Posted February 24, 2008 Share Posted February 24, 2008 Hi Everyone, I am realtivly new to PHP and i am currently trying to create a website for a friends company, i am at the moment working on the admin side i.e adding categories and products. I am currently trying to make a drop down list that will allow them to add a product to a category that already exsists, however i am having some problems with the code, could some please have a look at it and offer me some help? The code is below? <?php // Retrieve all the categories and add to the pull-down menu. $query = "SELECT category_id,category_name FROM category ORDER BY category_name"; $result = mysqli_query ($dbc, $query); while ($row = mysqli_fetch_array ($result)) { echo "<option value=\"{$row['category_name']}\">{$row['category_id']}</option>\n"; } mysqli_close($dbc); // Close the database connection. ?> Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 24, 2008 Share Posted February 24, 2008 What is the problem with the code? <?php // Retrieve all the categories and add to the pull-down menu. $query = mysqli_query("SELECT `category_id`, `category_name` FROM `category` ORDER BY `category_name` ASC", $query); //Make sure it's being orderd b ASC or DESC. Also try using as little variables as possible to save memory. while ($row = mysqli_fetch_array ($result)) { echo "<option value=\"{$row['category_id']}\">{$row['category_name']}</option>\n"; // I think you meant to put catagory_id and catagory_name the other way round. } mysqli_close($dbc); // Close the database connection. ?> Quote Link to comment Share on other sites More sharing options...
phpBegginer Posted February 24, 2008 Author Share Posted February 24, 2008 Thanks for the quick reply, the problem is that the drop down list doesn't seem to populating, i have tried you suggeston and still nothing any other ideas? I am at my wits end. Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 24, 2008 Share Posted February 24, 2008 Try this too and see if it returns an error: <?php // Retrieve all the categories and add to the pull-down menu. $query = mysqli_query("SELECT `category_id`, `category_name` FROM `category` ORDER BY `category_name` ASC", $dbc) or die(mysql_query()); //Make sure it's being orderd b ASC or DESC. Also try using as little variables as possible to save memory. while ($row = mysqli_fetch_array ($result)) { echo "<option value=\"{$row['category_id']}\">{$row['category_name']}</option>\n"; // I think you meant to put catagory_id and catagory_name the other way round. } mysqli_close($dbc); // Close the database connection. ?> Quote Link to comment Share on other sites More sharing options...
phpBegginer Posted February 24, 2008 Author Share Posted February 24, 2008 Got the following error... Parse error: syntax error, unexpected '?' inc:\wamp\www\JetStore\admin.php on line 128 i presume that beacuse we are using the msql or die it must be a problem with my SQL? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.