472,119 Members | 2,067 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Comparing Data in two tables,

Hi, i was wondering if anyone would be able to help me with a problem
i'm having,

I currently have two tables, in a database, one is Called products, and
one is called groupproducts, their are multiple groups which can be
added to or removed from.

I want to creat a screen which lists all of the products and then
places a tick in a tick box if that products in the specified group.
From this i'd submit it to another page which update the group

products.

I'm currently doing the same system but having to edit it on a product
by product basis which is very time consuming!

Any suggestions would be appreciated.

Thanks

Ian

Jul 17 '05 #1
2 1504
On 17 Jun 2005 02:27:42 -0700, in comp.lang.php "Ian N"
<ia*******@gmail.com> wrote:
| Hi, i was wondering if anyone would be able to help me with a problem
| i'm having,
|
| I currently have two tables, in a database, one is Called products, and
| one is called groupproducts, their are multiple groups which can be
| added to or removed from.
|
| I want to creat a screen which lists all of the products and then
| places a tick in a tick box if that products in the specified group.
| >From this i'd submit it to another page which update the group
| products.
|
| I'm currently doing the same system but having to edit it on a product
| by product basis which is very time consuming!
|
| Any suggestions would be appreciated.


Updating multiple records from a single form is pretty easy (when you
know how) :-)

The trick is that you will need to associate the groupproducts
controls with each product. You can do this by:
<input name="prod<%php echp productid%>" value="<?php echo
productid%>|<%php echo groupdid%>" ...
This will result in the html code of:
<input name="prod101" value="101|1" ...
<input name="prod101" value="101|9" ...
<input name="prod101" value="101|5" ...
<input name="prod222" value="222|1" ...
<input name="prod222" value="222|9" ...
<input name="prod222" value="222|5" ...
When the form is submitted you will see this list of values which can
be exploded to separate the info.

The only problem here is that the names are dynamically generated so
you will not know, in advance, what to process. You will need to loop
through the $_GET or $_PUT item to extract this info.
The $_GET will look like:
&prod101=101|1&prod101=101|9&prod222=222|5&prod222 =222|9

(my php is pretty woeful so I wont even attempt at giving you so
sample code).
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 17 '05 #2
Jeff North wrote:
The trick is that you will need to associate the groupproducts
controls with each product. You can do this by:
<input name="prod<%php echp productid%>" value="<?php echo
productid%>|<%php echo groupdid%>" ...
This will result in the html code of:
<input name="prod101" value="101|1" ...
<input name="prod101" value="101|9" ...
<input name="prod101" value="101|5" ...
<input name="prod222" value="222|1" ...
<input name="prod222" value="222|9" ...
<input name="prod222" value="222|5" ...
When the form is submitted you will see this list of values which can
be exploded to separate the info.


Unfortunately, if your code looks like this, then only the last input
with the same name will have anything in it.

What you should do is use arrays for your input name:
echo '<input name="prod[' .$productid. '][]" value="' . $productid .
'|' . $groupid .'">';

When you're writing/debugging the code, first make a dummy script
instead of the real processing script. In this dummy script, just put a
dump of the $_POST array:

<?php
echo '<pre>'; print_r ($_POST); echo '</pre>';
?>

This will show you what is being passed to your script. The you can
start actual coding.

Ken

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

41 posts views Thread by Odd-R. | last post: by
4 posts views Thread by osmethod | last post: by
2 posts views Thread by Shum | last post: by
8 posts views Thread by irek.szczesniak | last post: by
5 posts views Thread by Franck | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.