SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    accessing while loop variables

    PHP Code:
                    <font class="main_header">Tips  <?php echo "HI" ?>:</font><br><br>
                    <table border="0" bgcolor="#000000" cellpadding="4" cellspacing="1" align="left">
                        
                    <?
                    
                    
    while ($row mysql_fetch_array($result))
                        {
                    
    mysql_select_db("main");
                    
    $username_result safe_query("SELECT username FROM user WHERE userid='".$row["userid"]."'");
                    
    extract(mysql_fetch_array($username_result));
                    print 
    " <tr>\n";
                    print 
    "  <td  bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">Author:</font></td>\n";
                    print 
    "  <td bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\"><a href=\"/forums/member.php?s=&action=getinfo&userid=".$row["userid"]."\">".$username."</font></a> <font class=\"standard\">&nbsp;&nbsp;".$row["date"]."</font></td>\n";
                    print 
    " </tr>\n";
                    print 
    " <tr>\n";
                    print 
    "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">Zone:</font></td>\n";
                    print 
    "  <td bgcolor=\"#BCBCBC\" align=\"left\"><font class=\"standard\">".stripslashes($row["zone"])."</font></td>\n";
                    print 
    " </tr>\n";
                    print 
    " <tr>\n";
                    print 
    "  <td valign=\"top\" bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">Tip:</font></td>\n";
                    print 
    "  <td valign=\"top\" bgcolor=\"#ABABAB\" align=\"left\"><font class=\"standard\">".stripslashes($row["tip"])."</font></td>\n";
                    print 
    " </tr>\n";
                    print 
    " <tr>\n";
                    print 
    "  <td bgcolor=\"#BCBCBC\" align=\"left\">&nbsp;</td>\n";
                    print 
    "  <td bgcolor=\"#BCBCBC\" align=\"left\">&nbsp;</td>\n";
                    print 
    " </tr>\n";
                    }
                    
    ?>

                    </table>
    How can I print out the variable $row["zone"] before the while loop? If I fetch the array of the result before it is done in the while loop, the most recent entry is missing because I have used it to get the zone. I want to print this where it says "HI" and also as the page title.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Wolverhampton, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ermmmmmmmm, you can use mysql_fetch_array($result) and then after that you can reset the array to the first element by:

    a) mysql_data_seek($resul, 0); or
    b) dammit i can't remember it, but there is another one you can use... //what is it?????? grrrrrrrr

    beachball

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Wolverhampton, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the other is reset($row) if it's $row = mysql_fetch_array($result); but this might not work :S


    beachball

  4. #4
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The data seek worked! So it just returned to the front of the array, since I guess it was starting at the 2nd when I was using it in the loop?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Wolverhampton, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, mysql_data_seek($result, $number) moves the internal array pointer (what element it is currnetly on) of the result set $result to element $number in the array...

    summin' like that neway

    beachball


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
  •