SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict mcrumlish's Avatar
    Join Date
    Jan 2002
    Posts
    384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help me: Can someone help me with some PHP code?

    Hi,
    can someone please help me with this PHP code? I am a newbie but I need this urgently.

    I want some code for a loop. The loop will iterate a certain number of times, defined by a mySQL database entry.

    The loop will be outputting HTML to the screen into a table. I need the loop to, after it reaches 20 cells across, automatically start a new row. The table will be 20 cells across and 10 rows deep.

    I also need the loop to check a DB entry. If that entry is 1 it will produce HTML code A, if it is 0 the lopp will output HTML code B.

    I am really stuck with this so can someone help please.

    Thanks

    To summarise:
    The loop beings and sees it has to iterate "loopnumber" times where loopnumer is a mySQL DB entry
    In each iteration of the loop there will be a condition:

    if(status=1)
    output HTML A
    else
    output HTML B

    (status is a variable that is set to a mySQL DB entry "status")

    Also, I want it to check that 20 cells across have been output. Once it reaches 20 cells in a row it outputs HTMLO code to start a new table row.


    I have the pseudo code and theory for this right in my head but I cant get it working in PHP.

    Thanks for your help,

    //Martin

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have not had a chance to check this, but this is what I came up with quickly. You may have to tweak it and I'm sure there's a better way to write this, but it might get you started:
    PHP Code:
    <?php 
    $q1res 
    mysql_query("SELECT status FROM statustable");
    $row 1?>
    <tr>
    <?php 
    while($row <= 20) {
        if(
    $row 20) {
            
    $row 1;
            }
        else {
            
    $row $row 1;
            }
        while(
    $q1arr mysql_fetch_array) {
            if(
    $qlarray['status'] == 1) {
            
    ?>
            <td class="1">&nbsp;</td>
            <?php
            
    } else {
            
    ?>
            <td class="2">&nbsp;</td>
            <?php
            
    }
        }
    }
    ?>
    </tr>
    HTH.
    Sketch
    Aaron Brazell
    Technosailor




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
  •