Page 1 of 1

Suggestions?

Posted: Thu Dec 16, 2004 2:07 pm
by patch2112
Hello All,

I was wondering if anyone had any ideas how to best accomplish something. I'm making an ordering system for an embroider. I'm at the part where I need to allow the user to enter a name that is going to be embroidered on each article, specific to size/color.

I'm creating a form based off a MySQL query that contains: Quantity, Size, Color. I am going to use the Quantity to create a line on the form for each item. (ie if the quantity=10 then there will be ten lines). Each line will have a textbox, the Size and the Color (so they can get the right name on the right size/color).

Code: Select all

#select all the quantities/size/color combos for this item
$sql_combos = mysql_query("select quantity, color, size from cart_contents where item_number = "762B" ");

while ( $row = mysql_fetch_array($sql_combos) )
{
for ($i=0;$i<$row&#1111;"quantity"];$i++)
&#123;
&#125;
&#125;
There can be more than one row returned is why I have the WHILE in there.

My question is, how can I get all of the info out of the form? I need to gather the size, color and text on each line of the form, which as you can see is dynamically populated.

Should I try arrays inside of arrays or joining arrays? I'm using SESSIONS too, but there could be 100+ items. I really have no clue, so any help is greatly appreciated, as always.

Philip

Posted: Thu Dec 16, 2004 2:56 pm
by rehfeld
yes youll need to use arrays, or give unique names to each form field so that you can group them together

Code: Select all

&lt;input name="itemid&#1111;]" value="apple"&gt; &lt;input name="color&#1111;]" value="red"&gt;
&lt;input name="itemid&#1111;]" value="orange"&gt; &lt;input name="color&#1111;]" value="orange"&gt;
&lt;input name="itemid&#1111;]" value="grape"&gt; &lt;input name="color&#1111;]" value="purple"&gt;

Code: Select all

<?php


for ($i=0; isSet($_POST['itemid'][$i]); $i++) {
    echo 'this item name is '.$_POST['itemid'][$i] .' and its color is '.$_POST['color'][$i].'<br>';
}

?>
you could also use a different approach

Code: Select all

&lt;input name="itemid-0" value="apple"&gt; &lt;input name="color-0" value="red"&gt;
&lt;input name="itemid-1" value="orange"&gt; &lt;input name="color-1" value="orange"&gt;
&lt;input name="itemid-2" value="grape"&gt; &lt;input name="color-2" value="purple"&gt;

Code: Select all

<?php

for ($i=0; isSet($_POST["itemid-$i"]); $i++) {
    echo 'this item name is '.$_POST["itemid-$i"] .' and its color is '.$_POST["color-$i"].'<br>';
}





?>
and also like you mentioned, nested arrays would work as well.

Posted: Thu Dec 16, 2004 3:31 pm
by patch2112
Thank you SO much rehfled for taking the time. Really, thanks.
Philip