Jump to content

Drop down lists from a database


dude_se

Recommended Posts

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.

 

Link to comment
Share on other sites

$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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.