Suggestions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
patch2112
Forum Commoner
Posts: 86
Joined: Sun Oct 31, 2004 9:44 am
Location: London

Suggestions?

Post 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
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
patch2112
Forum Commoner
Posts: 86
Joined: Sun Oct 31, 2004 9:44 am
Location: London

Post by patch2112 »

Thank you SO much rehfled for taking the time. Really, thanks.
Philip
Post Reply