maffew wrote:
> I'm working from the excellent "PHP web development with
Dreamweaver MX 2004"
> book
Glad you like it. That case study was originally meant to be
about 40
pages, but like Topsy, it just growed and growed. :)
> It suggests adding a field to the category table which
will contain a number
> relating to its importance. (I've used a varchar type!
named "display_order")
VARCHAR is a bad choice for that type of column because it's
for text.
Consequently, item 11 will come before item 2! Use INT or
TINYINT instead.
> To this form I have added the display_order which needs
to be editable so I
> can alter the display_order. (I've included a
hiddenfield of the category_ID on
> the table row before the "repeat region"! Is this
right?)
It's a long time since I worked on it, but what I had in mind
was
something I have created on a separate website. I have a
different page
for setting the display order. All the items are displayed in
a repeat
region with a text input field alongside them for the display
order
number. The name of the text input field has square brackets
after it,
so it creates an array display_order[]. Inside the repeat
region, I
created another array made up of the category IDs. Then at
the bottom of
the page, I used this:
<input name="cat_id" type="hidden" value="<?php echo
implode(',',
$cat_id); ?>" />
When you submit the form, you then use explode() to turn
cat_id back
into an array. This leaves you with two arrays: display_order
and
cat_id. You can then use a loop like this:
for ($i = 0; $i < count($cat_id); $i++) {
$sql = 'UPDATE table SET display_order =
'.$_POST['display_order'][$i].' WHERE cat_id = '.$cat_id[$i];
mysql_query($sql);
}
> Is it possible to have 2 sumit buttons on 1 form? 1
button to delete records
> and 1 to update records!
Yes. Give the submit buttons different names. Then use this
to
distinguish between them:
if (array_key_exists('delete', $_POST)) {
// delete code goes here
}
elseif (array_key_exists('update', $_POST)) {
// update code goes here
}
--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/