SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: A little help

  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    WV,SC
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little help

    Ive been trying to get this code to work and ive looked at other post and tutorials with no luck. Can someone tell me if this code is right. or what im doing wrong.. WHen i view it it just repeats the color echo and freezes the window.
    Thanks

    PHP Code:
    <table width="300" height="400"> 
    <? 
    // Connect to MySQL 
    mysql_connect ('localhost''blank''blank') ; 
    mysql_select_db ('mysite'); 

    $query "SELECT title, news, author, date FROM news ORDER BY id DESC LIMIT 3"
    $result mysql_query($query); 

    if (
    $row mysql_fetch_array($result)) { 
        
    //run the for loop 
        
    for ($i 0count($row); $i++) { 
         
    // Set Table Row Color 
             
    if ($i 2) { 
                 echo 
    "<tr bgcolor=B0C4DE>"
             } else { 
                 echo 
    "<tr bgcolor=FOF8FF>"
             } 
            
    // Now display our table cell info 
        


    ?> 
    <td><? echo $row["<TR>
            <TD><b>Posted on 
    $date</b></TD> 
        </TR> 
        
        <TR>  
            <TD><b>Title:</b>
    $title</TD> 
        </TR> 
        <TR>
            <TD><b>News:</b>
    $news</TD> 
        </TR> "
    ]; 
        
    ?></td> 

    </table> 
    <? 
    ?>

  2. #2
    SitePoint Enthusiast webchick's Avatar
    Join Date
    Jun 2004
    Location
    in front of a computer
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're missing a $ right before the

    PHP Code:
     i count($row
    That makes the loop not know when to stop.

  3. #3
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically its:
    PHP Code:
    $i count($row
    On line 11 (including comments and spaces).

    Also, why have you got 3 sets of php? I mean why is there 3 blocked of code enclosed in <?php and ?>. Im not saying its wrong, ive just never come across it before?

  4. #4
    SitePoint Member
    Join Date
    Jun 2004
    Location
    WV,SC
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    i redid some of it. but now its only showing 1 post when my limit is set to 2. any ideas?

    PHP Code:
    <table width="200" height="100"> 
    <? 
    // Connect to MySQL 
    mysql_connect ('localhost''spl''') ; 
    mysql_select_db ('mysite'); 

    $query "SELECT `title`,`news`,`date` FROM `news` ORDER BY `ID` DESC LIMIT 2";

    $result mysql_query($query);
     

    if (
    $row mysql_fetch_array($result)) { 
        
    //run the for loop 
        
    for ($i 0$i count($row); $i++) { 
         
    // Set Table Row Color 
             
    if ($i 2) { 
                 echo 
    "<tr bgcolor=FOF8FF>"
             } else { 
                 echo 
    "<tr bgcolor=B0c4de>"
             } 
            
    // Now display our table cell info 
        


    ?> 
    <td><? 
    echo "<p><tt>Posted On :";
    echo 
    $row["date"];
    echo 
    "</tt></p>";

    echo 
    "<p><tt>Title:";
    echo 
    $row["title"];
    echo 
    "</tt></p>";


    echo 
    "<p><tt>News:";
    echo 
    $row["news"];
    echo 
    "</tt></p>";

        
    ?></td> 

    </table> 
    <? 
    ?>

  5. #5
    SitePoint Enthusiast webchick's Avatar
    Join Date
    Jun 2004
    Location
    in front of a computer
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spl
    PHP Code:
        for ($i 0$i count($row); $i++) {
         
    // Set Table Row Color
             
    if ($i 2) {
                 echo 
    "<tr bgcolor=FOF8FF>";
             } else {
                 echo 
    "<tr bgcolor=B0c4de>";
             }
            
    // Now display our table cell info
        

    That last } is a problem, as it ends the for loop. Try moving it just above </table> (which should probably actually be </tr></table>, since you start a row above but don't seem to end it)


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
  •