Jump to content


Photo

Checkboxs and URL's


  • Please log in to reply
2 replies to this topic

#1 robcrozier

robcrozier
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 31 March 2006 - 07:56 PM

Hi,

right what i've got is a large print out of info from one of my database tables and what i want to do is to create a checkbox next to each row that is printed out. i want to then be able to select one or more of these checkboxes and click a button which will send all of the values from the checkboxes throught the URL to another page. All of the chexkboxes will use the same table datum to pass throught the url but, being the primary key, each value will be different.

heres some code that ive got so far. This prints out all of the entries and places a checkbox next to each one:

<?php
echo "<br>";
echo "<center><table width = '100%' align ='center'><tr><td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Number :<b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Username :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>DVD Title :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Date :</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Sent:</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Recieved:</b></font></td>";

  while($nt=mysql_fetch_array($r))
  {
    echo "<tr>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_number]</td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'><a href='view_customer_records.php?username=$nt[username]'>$nt[username]</a></font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[dvd_title]</font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_date]</font></td>
<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>

<form name='sent' action='update_sent_orders.php' method='POST'>
<div align='center'><br>
<input type='checkbox' name='sent' value='$nt[order_number]'></div></form> </font></td>


<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>

<form name='recieved' action='update_recieved_orders.php' method='POST'>
<div align='center'><br>
<input type='checkbox' name='sent' value='$nt[order_number]'></div></form></font></td>
<td align ='left' width ='20%'><a href='delete_order.php?order_number=$nt[order_number]'>Delete</a></td></tr>";
  }
  echo"</center></table>";

  ?>


what i need help with is adding the final button which will send all of the information and also guidance on how to send the stuff through the url.

Note: the order number is the value i want to send!

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 31 March 2006 - 10:01 PM

Well first off you cannot have 2 forms an a page. You will have to do it with one for.

You will have to update sent and recieved orders on the same page. Good news is that it is easily done

I do not knwo what your pages are called but here is what I did

orders.php //just a name i gave it
<?
// Start your checkbox numbers, They cannot be the same name
$s = '1';
$re = '1';
echo "<br>";
echo "<center><table width = '100%' align ='center'><tr><td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Number :<b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Username :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>DVD Title :</b></font></td>
<td width = '20%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Order Date :</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Sent:</b></font></td>
<td width = '10%'><font size = '-1' color='#66FF66' face='Arial, Helvetica, sans-serif'><b>Recieved:</b></font></td>";

  while($nt=mysql_fetch_array($r))
  {
    echo "<tr>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_number]</td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'><a href='view_customer_records.php?username=$nt[username]'>$nt[username]</a></font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[dvd_title]</font></td>
<td width = '20%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'>$nt[order_date]</font></td>
<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'></td>

<form name='sent' action='update_orders.php' method='POST'>
<div align='center'><br>
<input type='checkbox' name='sent".$s."' value='$nt[order_number]'></div></font></td>
<td width = '10%'><font size = '-1' face='Arial, Helvetica, sans-serif' color='#D4ECFB'></td>
<div align='center'><br>
<input type='checkbox' name='rec".$re."' value='$nt[order_number]'></div></form></font></td>
<td align ='left' width ='20%'><a href='delete_order.php?order_number=$nt[order_number]'>Delete</a></td></tr>";
// Add one to the names
$s++;
$re++;
}
echo"<tr><td colspan=7><input type=submit></td></tr></center></form></table>";
?>

update_orders.php
<?php
$ids = '';
$sarray = array();
$rarray = array();
$send = 'sent';
$receive = 'rec';
foreach ($_POST as $key => $value) {
  $ids .= "$key=$value&";
  if (substr($key, 0, 4) == $send) {
    $sarray[]= $value;
  }
  if (substr($key, 0, 3) == $receive) {
    $rarray[]= $value;
}
}
$sentids = implode(", ", $sarray);
$recids = implode(", ", $rarray);

// sent query
$update_sql = "UPDATE order SET
              sent = 'check' WHERE id IN ($sentids)";

// receive query
$receive_sql = "UPDATE order SET
              receive = 'check' WHERE id IN ($recids)";
?>

Hope that helps

Ray

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 31 March 2006 - 10:03 PM

Enclose all checkboxes in same form and name them as "sent[]" so they get posted in a single array.

I'm using POST but if you specifically want a querystring, use GET.

Here's a simplified snippet to show how it works
<?php

if (isset($_POST['sent'])) {
    foreach($_POST['sent'] as $ono) {
            echo "$ono<br>";
    }
}
?>
<FORM method='POST'>
<INPUT TYPE="CHECKBOX"  name="sent[]" value="1">One<BR>
<INPUT TYPE="CHECKBOX"  name="sent[]" value="2">Two<BR>
<INPUT TYPE="CHECKBOX"  name="sent[]" value="3">Three<BR>
<INPUT TYPE="SUBMIT"  name="submit" value="Submit">
</FORM>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users