SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with formatting

    I'm at learining php, had some prior backround with perl, but I cannot figure out how to do some basic things. I have a recordset being queried by php which is being pulled from a database. They are about 160 of them, and they are option boxes(checkboxes) which I am submitting to a database. The problem is that the list is too long, how do I format them into lets say in a table with 3 columns. The problem is I don't know how I would do this in a while loop.

    Thanks.

    Mike

  2. #2
    From downunder but sure 2 rise Hazardous's Avatar
    Join Date
    Aug 2003
    Location
    New Zealand
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you post your code you're using it would make it easier to help
    Hazardous
    My Blog

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    $db = mysql_connect($hostpc,$user,$passwd);
    mysql_select_db($database,$db);
    $result = mysql_query("SELECT code,name FROM yourtable;");
    if(mysql_num_rows($result)>0) {
    while ($i = mysql_fetch_row($result)) {
    if (has_to_go_with_a_checkbox) {
    echo "<input type=\"checkbox\" name=\"".$i[0]."\" value=\"".$i[0]."\" checked>".$i[1];
    } else {
    echo $i[1];
    }
    } else {
    echo "No records found!";
    }
    ?>

  4. #4
    From downunder but sure 2 rise Hazardous's Avatar
    Join Date
    Aug 2003
    Location
    New Zealand
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $db 
    mysql_connect($hostpc,$user,$passwd);
    mysql_select_db($database,$db);
    $result mysql_query("SELECT code,name FROM yourtable;");
    if(
    mysql_num_rows($result)>0) {
    echo 
    "<table><tr>";
    $count=0;
    while (
    $i mysql_fetch_row($result)) {
    if (
    has_to_go_with_a_checkbox) {

    if (
    $count==3){
    echo 
    "</tr><tr>";
    $count=0;
    }
    echo 
    "<td><input type=\"checkbox\" name=\"".$i[0]."\" value=\"".$i[0]."\" checked>".$i[1]."</td>;
    $count++;
    } else {
    $noncheckboxAr$i[1];
    }
    if (
    $count==1)
    echo "
    <td>&nbsp;</td><td>&nbsp;</td></tr></table>";
    else if(
    $count==2)
    echo "
    <td>&nbsp;</td></tr></table>";
    else echo "
    </tr></table>";

    foreach ( 
    $noncheckbox as $noncheckboxAr ) {
        echo 
    $noncheckbox."<br>;
    }

    } else {
    echo 
    "No records found!";
    }
    ?>
    not tested, but should work for you
    Hazardous
    My Blog


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •