admin page for category table


#1

I found some info about creating a category table like this

|cat_ID|Parent_ID|cat_name|

The information shows a pre populated table similar to this

|1|0|top|
|2|0|top|
|3|0|top|
|4|2|sub|
|5|2|sub|
|6|3|sub|
|7|5|subsub|
|8|5|subsub|

What I’m having trouble with is trying to picture how to put an admin page together to enter data into the database.

Has anyone done something like this that could shed some light on how it’s achieved?


#2

I’m thinking forum script if I see your DB structure like that ;) Correct me if I’m wrong.

I’ve given it a try awhile ago. You could use dropdowns in a form to select a certain item’s ‘parent name’, which behind-the-scenes is being converted to the parent_id. Just loop through the DB entries to retrieve all of the available parents.


#3

No it’s actually me reinventing the wheel to some extent. Not because I want to but because what exists won’t let me set it to what I require.

I’ts for a shopping cart of sorts. More a multi page/category order form. All that I need to do is email to base the number of items that people want of categorized products and all the rest is dealt with manually on site.

The website already exists but is needing to be redone to php/mysql from some other system, I’d send the link but it appears to be down right now

Basically it looks like this (Categories on the left, sub categories are used as headings with products coming underneath them. and the [ ] represents the box where you enter the quantity) (I had to edit the post as the layout did not stick, pretend the … are not there.0

CHOCOLATE…WRAPPED
SWEETS…Mars Bar [ ]
POPCORN…Pinky [ ]
SNACKS…BOXED
…Roses [ ]
…Cadbury [ ]

There are a lot of good shopping cart systems out there but i have not found one where I can set it to do what I need, basically get rid of the pricing and just email number of items through. So I’m attempting to write my own.


#4

using a form similiar to below:

<table width='100%' cellpadding=0 cellspacing=0 border=1 bordercolor='#eeeeee'><tr>
<form  name="frm" action="addcat.php" method="post"><td valign='top' align='center'>
Category:</TD>
<TD><input type="text" name="newcat" value=""></TD>
<TD><input type=submit value='Add Category' name='Submit'></TD>
</TR></form></table>

to insert into your database you would use something like this below:
[php]
$query = “INSERT INTO class_item (id,sub,cat) VALUES (’’,’$cat_id’,’$newcat)”;
mysql_query($query) or die(‘Error, query failed’);
echo “[ Posted Successfully ]
”;
[/php]

Or to update use something like this:

[php]
$query = “UPDATE category_table SET sub = ‘$main_category_id’, cat = ‘$new_cat_name’”;
$result = mysql_query($query) OR die(mysql_error());
[/php]

Or to delete use something like this:

[php]
$query = “DELETE FROM category_table WHERE id=’$id’”;
$result = mysql_query($query) OR die(mysql_error());
[/php]

You might find this tutorial for a news script interesting here at
http://www.maaking.com/index.php?loadpage=tutorials

when I try to find information like this, I try to look up on yahoo.com for “php tutorial, mysql delete” or “php tutorial, mysql insert” or so on… without the quotes ( " ).

(if someone wants to correct me on any of the above, please do, dont claim to be perfect, but these should work.)

Now remember, this is only to add, update, and delete your categories, not how to show them on your page… or counting.