Jump to content

Recommended Posts

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.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/171677-display-all-data-from-mysql-in-table/
Share on other sites

$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

$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

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.