Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Using List Data In Form

Codes here !

Moderators: macek, egami, gesf

Using List Data In Form

Postby rentonsa » Wed Aug 22, 2012 7:17 am

Hi folks

I'm a fairly limited php user, so accept that I'm trying to hack through something that could be done more elegantly.

I've generated a list of rows thus:

Code: Select all
$sql="select * from orders.ORDER where status = 'P'";
$result=mysql_query($sql) or die( "A MySQL error has occurred.<br />Your Query: " . $sql . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());

$num=mysql_numrows($result);

echo "number_of rows $num";
$i=0;

echo "<table><tr width = 30%><td><b>Order ID</b></td><td width = 40%><b>Shelfmark</td><td width = 30%><b>Page Number</td></tr>";
while ($i < $num)
  {
   $order_id= mysql_result($result, $i, "id");
   $shelfmark = mysql_result($result, $i, "shelfmark");
   $page_no = mysql_result($result, $i, "pageno");

   echo "<form method ='post' action = 'updateOrder.php'><tr><td><input type = text name = order_id size = 10 value= $order_id></td><td>$shelfmark</td><td>$page_no</td><td><input type = 'submit' value = 'update this order' name = 'button$i'></td></tr>";

    $i++;

  }


I thought if I made each row a form, with a button, I could pass the order id through to another page, where the order could be updated. It won't do that, as each button takes the value of order_id as it is (ie the last number)- I haven't attempted to do it using an array, as I assume I will hit the same problem with the counter value. Just wondering if anyone knows a (better) way to do this- I don't really want to use a dropdown for this.

Cheers
Scott
Attachments
Pending.png
Pending.png (19.95 KiB) Viewed 236 times
rentonsa
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Aug 22, 2012 7:09 am

Re: Using List Data In Form

Postby ourstore » Wed Aug 22, 2012 8:37 am

you must replace each form for a checkbox list and detect the selected checkboxes for update.
;)
User avatar
ourstore
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Aug 22, 2012 5:46 am
Location: NY

Re: Using List Data In Form

Postby rentonsa » Thu Aug 23, 2012 7:55 am

Thanks very much for that. I have changed to checkboxes and will see if I can get any further!
rentonsa
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Aug 22, 2012 7:09 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron