#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    30
    Rep Power
    0

    Displaying of records in html table randomly


    PHP Code:
    <?php 

    //Create the connection and select the DB 
    include('db_connect.php'); 

    // Select records from the DB 
    $query "SELECT * FROM tbl_product ORDER BY Rand() LIMIT 3"
    $result mysql_query($query); 

    echo 
    "<h1>Table: {$table}</h1>";
    echo 
    "<table border='1' cellpadding='2' cellspacing='2' width='100%'>";

    $counter 1;
    $htmlHolder1 "<tr>";
    $htmlHolder2 "<tr>";
    $htmlHolder3 "<tr>";
    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) {
        
    $htmlHolder1 .= "<td>".$row["image"]."</td>";
        
    $htmlHolder2 .= "<td>".$row["description"]."</td>";
        
    $htmlHolder3 .= "<td>".$row["link"]."</td>";
        
    $counter += 1;
        if(
    $counter 0)
        {
            echo 
    $htmlHolder1."</tr>";
            echo 
    $htmlHolder2."</tr>";
            echo 
    $htmlHolder3."</tr>";

            
    $htmlHolder1 "<tr>";
            
    $htmlHolder2 "<tr>";
            
    $htmlHolder3 "<tr>";
        }
    }
    if(
    $counter != 0)
    {
        echo 
    $htmlHolder1."</tr>";
        echo 
    $htmlHolder2."</tr>";
        echo 
    $htmlHolder3."</tr>";
    }
    echo 
    "</table>";
    ?>
    above code is not working to display records randomly

    anyone please help me out

    error at line if($counter % 3 = 0)
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,904
    Rep Power
    1045
    Instead of flooding the forum with 8 threads about the same 20 lines of code, how about you ask one good question?

    Take a deep breath, sit down and check your code very carefully. So you're saying "the code doesn't work"? I have no idea what that means. What is the problem? Is it a syntax error? A runtime error? Unwanted behaviour? A blank screen? You need to be more specific.

    OK, I guess PHP tells you there's a syntax error in this line:

    PHP Code:
    if($counter 0
    This means the parser cannot understand what you've written down. Look closely. Can you see it? Oops, you've used the assigment operator "=" instead of the equality operator "==".

    That wasn't too hard, was it? Debugging code is no rocket science. Learn it. And if you just cannot find the problem, even after 20 minutes of heavy debugging, take 5 minutes to ask a concrete question in the right thread.

IMN logo majestic logo threadwatch logo seochat tools logo