Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

checkbox query

Options
  • 05-04-2006 1:31pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    I have a select query to the effect of this:

    [PHP]$SQL="SELECT * FROM blah WHERE blah etc. etc.";
    $result = mysql_query($SQL) or die("Query failed : " . mysql_error());
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){

    print("<tr>");
    print("<td>".$row."</td>");
    print("<td>".$row."</td>");
    print("<td>".$row."</td>");
    print("<td>".$row."</td>");
    print("</tr>");

    }[/PHP]

    What that does is prints out a row for each result retrieved, so if there's two results there's only two rows, if there's twenty results there's twenty rows etc.

    What I need to know is how I can put a checkbox into that sequence of print commands so that each row gets a checkbox as well? Obviously since that whole section is php i cant just plonk the html in the middle of it... Any help appreciated, thanks!


Comments

  • Moderators, Politics Moderators Posts: 39,809 Mod ✭✭✭✭Seth Brundle


    add
    print("<td><input type=\"checkbox\" id=\"whatever\" value=\"whatever\"></td>");
    before
    print("</tr>");

    This will widen your table by one cell. You may need to add a form tag also.
    You could replace the value attributes value with the ID from the DB table.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Nice one, cheers!


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Ok so now i have this:

    [PHP]print("<td><input type=\"checkbox\" name=\"chk_id\" value=\"{$row}\" CHECKED></td>");[/PHP]

    The form action is to the next page, the method is post, and I wanted to create something like this:

    [PHP]if(isset($v)){

    foreach($v as $key=>$val) {
    if(substr($key,0,4)=="chk_"){
    $rnwl_id=val(substr($key,4));
    $sql="SELECT * FROM tbl_submission_transmission WHERE st_firm_id={$_SESSION} AND (st_id=$chk_id)";
    mysql_query($sql) or die("Query failed:" .mysql_error(). debug($sql));[/PHP]

    But that doesn't seem to want to work for me, chk_id doesn't seem to be passing correctly... :confused:


  • Closed Accounts Posts: 3,322 ✭✭✭Repli


    What's $v ?? Try $_POST["chk_id"] instead..


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Repli wrote:
    What's $v ?? Try $_POST["chk_id"] instead..
    lollers.

    Everyone asks me about $v! Its defined in functions.php as:

    [php]foreach($_REQUEST as $key=>$val) {
    $v[$key]=$val;
    $s[$key]=mysql_real_escape_string($val);[/php]
    Anyway I solved the problem last night. In the previous page I had:

    [php]<input type=checkbox name=chk_id value={$row}>[/php]
    when I should have had:

    [php]<input type=checkbox name=chk_{$row} value={$row}>[/php]


  • Advertisement
Advertisement