dude_se Posted October 27, 2010 Share Posted October 27, 2010 First of all id like to say hi, as im new here. this place looks pretty cool and im hoping it will help me with my work and in time i might be able to help others anyway just to set the background this is the assignment i have to do: Developing an Open Source shopping list application using PHP Your application should have the following functionality: The ability to: • Create, save, edit and delete shopping lists. • Add, delete, edit items on lists • Create, edit and delete categories for the lists. Where a list may have a number of categories and categories may have a number of items. Think of the categories as aisles or areas of the supermarket. It is important that a user can edit the order of categories and of items within categories. This allows a list to be formatted to suit different shops. You should use two CSS files, one for web viewing (mobile device compatible) and one for printing to A4. You must demonstrate the use of: XML or JSON, and OO techniques. I kind of had to jump in the deep end into my course, so whilst this may seem easy to you guys it isnt that easy for me. my plan was to create a database which will store everything in, and then the users can add and delete things (which ill have to figure out). i was thinking of having a drop down box which displays "add category, edit, delete, etc", then based on what the user clicks another box will come up, for example if you click add category a box will come up allowing you to type and submit a new category, or if you want to add to an existing one, you can select it from a drop down list and then some fields will appear and you can write in the data. would this work / are there any other ways of doing it? found some code on the net to produce drop down boxes but i cant get it working and its now making me wonder if i should keep trying it or if im just missing the task at hand all together, as there just isnt a lot of info on what to do. any help would be greatly appreciated, cheers. Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/ Share on other sites More sharing options...
Pikachu2000 Posted October 27, 2010 Share Posted October 27, 2010 Yes, doing what you propose with a select box should work just fine if done properly. If you're having problems with a specific piece of code, please post it and describe the problem you're having with it. Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127084 Share on other sites More sharing options...
dude_se Posted October 27, 2010 Author Share Posted October 27, 2010 $sql="SELECT Categories FROM members"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $Categories=$row["Categories"]; $options.="<OPTION VALUE=\"$Categories\">".'</option>';} ?> <select name='category'> <option value='0'>Choose an option <?=$options?> </select> seen a few bits of code, but this is the latest example I am messing about with. I have setup the connection to the db and as there are no errors I assume it connects, but on the webpage the drop down list is just blank. I am also very confused on how to layout the database. I need categories, and lists, etc. I really dont know how to lay it all out. Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127106 Share on other sites More sharing options...
Pikachu2000 Posted October 27, 2010 Share Posted October 27, 2010 I don't think your query is actually succeeding. Add some code to echo errors if the query fails. $sql="SELECT Categories FROM members"; $result=mysql_query($sql) or die( mysql_error() ); $options=""; while ($row=mysql_fetch_array($result)) { $Categories=$row["Categories"]; $options.="<OPTION VALUE=\"$Categories\">".'</option>';} ?> <select name='category'> <option value='0'>Choose an option <?php echo $options; ?> <!-- Changed this line to use full PHP tag syntax rather than "quick echo" syntax --> </select> EDIT: Moving thread to PHP Coding Help Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127112 Share on other sites More sharing options...
dude_se Posted October 27, 2010 Author Share Posted October 27, 2010 this is what happens http://bronzedog.co.uk/assign/members2.php all i did was change "choose" to "choose an option" so it seems to be connecting to the DB, but maybe im just not doing something right. edit: ignore the crappiness of the page. just want to get it working first Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127136 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2010 Share Posted October 27, 2010 This line is incomplete and is breaking your HTML - <option value='0'>Choose an option It should be - <option value='0'>Choose an option</option> Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127138 Share on other sites More sharing options...
Pikachu2000 Posted October 27, 2010 Share Posted October 27, 2010 Comment out the entire block of code above, and replace it with this. Let me know what happens. $sql="SELECT Categories FROM members"; $result=mysql_query($sql) or die( mysql_error() ); echo "<select name=\"category\">\n"; echo "<option value=\"0\">Choose an option</option>\n"; while ($row=mysql_fetch_array($result)) { echo "<OPTION VALUE=\"{$row['Categories']}\">{$row['Categories']}</option>\n"; } echo "</select>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127139 Share on other sites More sharing options...
dude_se Posted October 27, 2010 Author Share Posted October 27, 2010 ok it works now, thanks :) im just still very confused how i should lay it out, like what tables and fields i should have. Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127143 Share on other sites More sharing options...
Pikachu2000 Posted October 27, 2010 Share Posted October 27, 2010 You can drop OPTION VALUE to lower case. I guess somehow I ended up with caps lock on and didn't notice . . . Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1127146 Share on other sites More sharing options...
dude_se Posted October 29, 2010 Author Share Posted October 29, 2010 ok i can successfully add a new category, and view them. just not too sure how to approach: • Create, save, edit and delete shopping lists. • Add, delete, edit items on lists ive got a table at the moment with the categories in, my friend said why not just store it all in that table based on the category selected/the username. if a user can create several lists then i dont see how this will work, as to unless each time the user makes a list it gets its own ID or something? Ah I dont know what im saying. this is just confusing me. once i know how it should be layed out i can approach it a lot better. Quote Link to comment https://forums.phpfreaks.com/topic/216999-drop-down-lists-from-a-database/#findComment-1128046 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.