s4salman Posted February 11, 2009 Share Posted February 11, 2009 I use following code to print records from mysql table. but i want to display 5 records in one row. then next 5 records in 2nd row and so on. How this code will be changed. i m trying but all going wrong making me confused. Can any one help me? <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> <? $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo $first." ".$last; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $phone; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $mobile; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $fax; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo $email; ?>">E-mail</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo $web; ?>">Website</a></font></td> </tr> <? $i++; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/144803-print-into-html-table/ Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 Why do you want 5 records in 1 row? It is possible, but is there a particular reason why? To do it your table headings would no longer be valid, you would have to create 4 more duplicates of your th tags. Explain the reasoning behind it, as I see no logical or reasonable reason why you would want it done this way. Quote Link to comment https://forums.phpfreaks.com/topic/144803-print-into-html-table/#findComment-759858 Share on other sites More sharing options...
s4salman Posted February 11, 2009 Author Share Posted February 11, 2009 Actually i was talking about this : http://fun007.com/video.php?id=304 see the random funny video table in the center of the web page layout. i want to make that kind of table using above similar code because it is simple to undertsand for me. Quote Link to comment https://forums.phpfreaks.com/topic/144803-print-into-html-table/#findComment-759877 Share on other sites More sharing options...
premiso Posted February 11, 2009 Share Posted February 11, 2009 <table border="0" cellspacing="2" cellpadding="2"> <!-- commented out cause this would not be useful with new version<tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> --> <?php $i=0; $output = "<tr>"; while ($row = mysql_fetch_assoc($result)) { if (($i%5) == 0) { $output .= "</tr><tr>"; } $output .= <<<OUTPUT <font face="Arial, Helvetica, sans-serif">{$row['first']} {$row['last']}</font><br /> <font face="Arial, Helvetica, sans-serif">{$row['phone']}</font><br /> <font face="Arial, Helvetica, sans-serif">{$row['mobile']}</font><br /> <font face="Arial, Helvetica, sans-serif">{$row['fax']}</font><br /> <font face="Arial, Helvetica, sans-serif"><a href="mailto:{$row['email']}">E-mail</a></font><br /> <font face="Arial, Helvetica, sans-serif"><a href="{$row['web']}">Website</a></font></td> OUTPUT; $i++; } $output .= "</tr>"; // just incase echo "{$output}</table>"; ?> The <<<OUTPUT OUTPUT; is HEREDOC syntax, incase you were wondering. See if the above is what you want. Quote Link to comment https://forums.phpfreaks.com/topic/144803-print-into-html-table/#findComment-759887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.