beboo002 Posted September 5, 2007 Share Posted September 5, 2007 hello freaks i am fetch the value through database but unable to take in format what i am want here my fetching code while ($row2=mysql_fetch_array($res2)) { echo "<table width=100% cellpadding=0 cellspacing=0><tr><td><td><a href='home1.php?sub_cat_id=$row2[id]'>$row2[cat_name]</a></td></td></tr></table>"; //echo "<td></td><tr></tr>"; } and output came like this ------------------------ Animation Outsourcing Business Process Outsourcing Graphic Design and Multimedia Callcenter Outsourcing but i want result like this Animation Outsourcing Business Process Outsourcing Graphic Design and Multimedia Callcenter Outsourcing Quote Link to comment https://forums.phpfreaks.com/topic/68004-didnt-found-value-in-format-through-database/ Share on other sites More sharing options...
recklessgeneral Posted September 5, 2007 Share Posted September 5, 2007 Hi, The problem is that each row of your result set is appearing in its own table rather than a different rows of the same table. You want to do something like this: // Start table definition echo "<table>"; while ($row2=mysql_fetch_array($res2)) { echo "<tr>"; echo "<td><a href='home1.php?sub_cat_id=$row2[id]'>$row2[cat_name]</a></td>"; echo "</tr>"; } // end table definition echo "</table>"; However, this'll still produce results in one column, but at least they're all part of the same table. We can embellish this with basic structure by keeping a count of how many columns you want per row, and every time we reach that number we start a new row: $COLS_PER_ROW = 2; $colCount = 0; $numRows = mysql_num_rows ($res2); // Start table definition echo "<table>"; while ($row2=mysql_fetch_array($res2)) { // Start a row whenever our count is divisible by the number of items in each row if ($colCount % $COLS_PER_ROW == 0) { echo "<tr>"; } echo "<td><a href='home1.php?sub_cat_id=$row2[id]'>$row2[cat_name]</a></td>"; // End the row when the last space in the row has been filled, or when there are no more items in the result set. if ($colCount % $COLS_PER_ROW == $COLS_PER_ROW - 1 || $colCount == $numRows - 1) { echo "</tr>"; } $colCount++; } // end table definition echo "</table>"; This is based on some code I have for displaying picture thumbnails in a table for a photo gallery page on my website. Haven't tested the code snippet above so may contain the odd typo, but the structure is about right I reckon. Regards, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/68004-didnt-found-value-in-format-through-database/#findComment-341879 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.