pixeltrace Posted July 16, 2007 Share Posted July 16, 2007 hi, i need help, i have a page wherein the result listing needs to be displayed in 2 columns. let say i have a total count of 10, the first 5 will be displayed in the first column and the remaining 5 will be displayed in the next column. this is my current code and i cant seem to make it work <? $uSql = "SELECT * FROM jos_classifieds_categories WHERE parent = '$id' AND published=1 LIMIT 0,5"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; }else{ while($uRow = mysql_fetch_array($uResult)){ $name = $uRow["name"]; $subid = $uRow["id"]; echo " <table width='600' border='0' cellspacing='3' cellpadding='0'> <tr> <td><a href='test.php?id=$id&subid=$subid&view=subview'>$name</a></td> <td><a href='test.php?id=$id&subid=$subid&view=subview'>$name</a></td> </tr> </table> "; } } ?> hope you could help me with this. thanks! Link to comment https://forums.phpfreaks.com/topic/60179-solved-how-to-display-results-in-2-columns/ Share on other sites More sharing options...
pixeltrace Posted July 16, 2007 Author Share Posted July 16, 2007 Hi, Any help on this please? thanks! Link to comment https://forums.phpfreaks.com/topic/60179-solved-how-to-display-results-in-2-columns/#findComment-299420 Share on other sites More sharing options...
pixeltrace Posted July 16, 2007 Author Share Posted July 16, 2007 hi, i found a code that displays result in 2 columns but i still cant make it work normally what i wanted to happen is if i have 10 results the display will look like this result1 result6 result2 result7 result3 result8 result4 result9 result5 result10 and currently this is the code that i have <?php $columns = 2; $sql = "SELECT * FROM jos_classifieds_providers WHERE published=1"; $result = mysql_query($sql) or die("Couldn't execute query."); $num_rows = mysql_num_rows($result); $rows = ceil($num_rows / $columns); while($row = mysql_fetch_array($result)) { $data[] = $row['name']; $data1[] = $row['address']; $data2[] = $row['postalcode']; } echo "<table border='0'>n"; for($i = 0; $i < $rows; $i++) { echo "<tr>n"; for($j = 0; $j < $columns; $j++) { if(isset($data[$i + ($j * $rows)])) { echo "<td><img src="" . $data[$i + ($j * $rows)] . ""></td>n"; echo "<td valign="top">" . $data1[$i + ($j * $rows)] . "<br>" . $data2[$i + ($j * $rows)] . "</td>n"; } } echo "</tr>n"; } echo "</table>n"; ?> but i am getting an error Parse error: parse error, unexpected '\"', expecting ',' or ';' in /var/www/html/myoochi/findit/test2.php on line 29 and this is my testpage link http://mango.resonance.com.sg/myoochi/findit/test2.php hope you could help me with this. thanks! Link to comment https://forums.phpfreaks.com/topic/60179-solved-how-to-display-results-in-2-columns/#findComment-299427 Share on other sites More sharing options...
sasa Posted July 16, 2007 Share Posted July 16, 2007 try <?php $columns = 2; $sql = "SELECT * FROM jos_classifieds_providers WHERE published=1"; $result = mysql_query($sql) or die("Couldn't execute query."); $num_rows = mysql_num_rows($result); $rows = ceil($num_rows / $columns); while($row = mysql_fetch_array($result)) { $data[] = $row['name']; $data1[] = $row['address']; $data2[] = $row['postalcode']; } echo "<table border='0'>\n"; for($i = 0; $i < $rows; $i++) { echo "<tr>\n"; for($j = 0; $j < $columns; $j++) { if(isset($data[$i + ($j * $rows)])) { echo "<td><img src=\"" . $data[$i + ($j * $rows)] . "\"></td>\n"; echo "<td valign=\"top\">" . $data1[$i + ($j * $rows)] . "<br>" . $data2[$i + ($j * $rows)] . "</td>\n"; } } echo "</tr>\n"; } echo "</table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/60179-solved-how-to-display-results-in-2-columns/#findComment-299483 Share on other sites More sharing options...
pixeltrace Posted July 17, 2007 Author Share Posted July 17, 2007 thanks its working now! Link to comment https://forums.phpfreaks.com/topic/60179-solved-how-to-display-results-in-2-columns/#findComment-300018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.