Forum Moderators: coopster

Message Too Old, No Replies

How to use radio buttons to ID a mysql row

         

replica2u

12:44 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



In shipment table, there are 2 rows:

1. EMS shipment
2. Registered post

In order.php, customer can select above shipment type. So, I add 2 radio buttons to select the row in mysql.

echo"<tr bgcolor='$colour_1'>
<td align='right' valign='middle' colspan='3' rowspan='2'><font color=\"#990000\">*</font> <b>$la_ship_type_select:</b></td>
<td valign='middle' colspan='3'><input name=\"shipment\" type=\"radio\" value=\"post\" checked>$la_registered_post</td>
</tr>
<tr bgcolor='$colour_1'>
<td valign='middle' colspan='3'><input name=\"shipment\" type=\"radio\" value=\"ems\">$la_ems</td>
</tr>";

----------

CODE?>
<script language="JavaScript">
<?
$resulta=mysql_query("select * from ".$prefix."store_shipzones order by zone_id");

echo "var shipping_costs_array=Array()\n";
while($line=mysql_fetch_array($resulta)) {
echo "shipping_costs_array['".$line['zone_name']."']=".$line[$ship_price]."\n";
}

How do I reference the radio buttons to reflect the $ship_price.

coopster

3:43 pm on Nov 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would move the SQL logic up in the code earlier, before you echo out the <input> elements. Build the input elements AND the JavaScript at the same time (make each it's own variable). Then, when you start printing out the HTML, echo your PHP variables accordingly.

replica2u

6:10 pm on Nov 4, 2006 (gmt 0)

10+ Year Member



echo"<tr bgcolor='$colour_1'>
<td align='right' valign='middle' colspan='3' rowspan='2'><font color=\"#990000\">*</font> <b>$la_ship_type_select:</b></td>
<td valign='middle' colspan='3'><input name=\"shipment\" type=\"radio\" value=\"post\" checked>$la_registered_post</td>
</tr>
<tr bgcolor='$colour_1'>
<td valign='middle' colspan='3'><input name=\"shipment\" type=\"radio\" value=\"ems\">$la_ems</td>
</tr>";

The original code to print on screen:

echo "shipping_costs_array['".$line['zone_name']."']=".$line['ship_price']."\n";

Where:

1. zone_name - shipment zone
2. ship_price - EMS shipment price
3. post - registered post price

I try to change the code as follow:

if ($shipment=='post');
{
echo "shipping_costs_array['".$line['zone_name']."']=".$line['post']."\n";
}
if ($shipment=='ems');
{
[b]echo "shipping_costs_array['".$line['zone_name']."']=".$line['ship_price']."\n";[/b]
}

It will only read the last code (bold). I think must be wrong with radiobutton object cause I'm not sure how to use it.

Please help.