MDanz Posted August 24, 2009 Share Posted August 24, 2009 i've done this so far, but it only displays 1 row of the database. <?php session_start(); mysql_connect("localhost", "Master", "password"); mysql_select_db("db"); if ($_SESSION['username']){ $query = mysql_query("SELECT * FROM castack"); if (mysql_num_rows($query)==0) die("Stack not found!"); else { $row = mysql_fetch_assoc($query); $username = $row['username']; $stackname = $row['name']; echo "<a href='http://www.nfjslnf.com/search.php?search=$stackname' style='text-decoration: none';><table border='0' celpadding='0' cellspacing='0'> <tr> <td width='101px' height='101px' background='Stacks/template.jpg' VALIGN='middle'> <font color=black font size=3 font face=Arial><center><b>$stackname</b></center></font></td> </td> </tr> </table></a>"; }} ?> i'd like it to display all the results in a table. and the limit is 8 columns. Once the results get to 8 columns then a new row is started. Quote Link to comment https://forums.phpfreaks.com/topic/171677-display-all-data-from-mysql-in-table/ Share on other sites More sharing options...
mikesta707 Posted August 24, 2009 Share Posted August 24, 2009 you have to iterate through the array. while($row = mysql_fetch_assoc($query)){ $username = $row['username']; $stackname = $row['name']; echo $username; echo "<br />"; echo $password; } Quote Link to comment https://forums.phpfreaks.com/topic/171677-display-all-data-from-mysql-in-table/#findComment-905259 Share on other sites More sharing options...
MDanz Posted August 24, 2009 Author Share Posted August 24, 2009 thx it worked how do i display all the results in a table and the limit is 8 columns. Once the results get to 8 columns then a new row is started? Quote Link to comment https://forums.phpfreaks.com/topic/171677-display-all-data-from-mysql-in-table/#findComment-905263 Share on other sites More sharing options...
mikesta707 Posted August 24, 2009 Share Posted August 24, 2009 $count = 0; echo "<table><tr>"; while($row = mysql_fetch_assoc($query)){ $username = $row['username']; $stackname = $row['name']; echo "<td>" echo $username; echo $password; echo "<td>" if (($count % == 0){ echo "</tr><tr>"; } $count++; } that should work. I didn't test it though, so it might be a little off syntactically Quote Link to comment https://forums.phpfreaks.com/topic/171677-display-all-data-from-mysql-in-table/#findComment-905270 Share on other sites More sharing options...
MDanz Posted August 24, 2009 Author Share Posted August 24, 2009 $count = 0; echo "<table><tr>"; while($row = mysql_fetch_assoc($query)){ $username = $row['username']; $stackname = $row['name']; echo "<td>"; echo "<a href='http://www.sfdffasfs.com/search.php?search=$stackname' style='text-decoration: none';><table border='0' celpadding='0' cellspacing='0'> <tr> <td width='101px' height='101px' background='Stacks/template.jpg' VALIGN='middle'> <font color=black font size=3 font face=Arial><center><b>$stackname</b></center></font></td> </td> </tr> </table></a>"; echo "<td>"; if (($count % == 0){ echo "</tr><tr>"; } $count++; } } } k thx for help... i've implemented it into my code.. its displaying like this(L represents picture. L LL When i want it 8 column, then new row LLLLLLLL etc Quote Link to comment https://forums.phpfreaks.com/topic/171677-display-all-data-from-mysql-in-table/#findComment-905285 Share on other sites More sharing options...
mikesta707 Posted August 24, 2009 Share Posted August 24, 2009 well, you close your table tags inside the loop itself... and you have a bunch of different <tr> tags inside the loop, as well as 2 extra curly brackets that I have no idea where they came from. And another echo of a <td> tag that I can't really see a use for. You are going to have to try implementing my code that I wrote in a much different way because as it stands right now, I have no clue what you are doing inside that while loop. its a mess Quote Link to comment https://forums.phpfreaks.com/topic/171677-display-all-data-from-mysql-in-table/#findComment-905301 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.