i want to display 2 or more records per row

Discussion in 'PHP' started by Kyriakos, May 2, 2008.

  1. #1
    hi,

    i want to display 2 or more records per row. in asp it's working fine. this is the asp code for 3 records per row:
    <table>
    <tr>
    <% while not RS.EOF %>
    <% if count mod 3 = 0 then response.write("</tr><tr>") end if%>
      <td width="33%" align="center" valign="bottom" bgcolor="#f7ffff"><%=RS("product_name")%></td>
      <%count = count + 1
    RS.MoveNext
    WEND%>
      </tr>
    </table>
    HTML:
    can anyone convert this to php?

    thanks in advance!
     
    Kyriakos, May 2, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    $con = mysql_connect("localhost","username","PASS");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("dbname", $con);
    $result=mysql_query("select * from table");
    $num_rows = mysql_num_rows($result);
    $count=0;
    echo "<table><tr>";

    if ($num_rows>0)
    {
    while($row = @mysql_fetch_array($result)){

    if (count % 3 == 0)
    echo("</tr><tr>");
    echo " <td width=\"33%\" align=\"center\" valign=\"bottom\" bgcolor=\"#f7ffff\">".$row["product_name"]."</td>"; $count = $count + 1;
    }
    }
    mysql_close($con);

    }
     
    kmap, May 2, 2008 IP
  3. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you want this:
    
    <table>
      <tr>
    <?php
    $select = mysql_query("SELECT * FROM `news`");
    while($row = mysql_fetch_array($gamedt)){
    $news = $row['news'];
    ?>
    
        <td width="16%"><div align="center"><? echo $news; ?></td>
        <?
    if (++$rowcount % 2 == 0)  {    
    echo '</tr><tr>';    
    }
    }
    ?>
      </tr>
    </table>
    
    
    PHP:
     
    shotazi, May 2, 2008 IP