Jump to content

php to create a table displayed on page


Greaser9780

Recommended Posts

Where do you pull the clan names from? database or do you just type them in a array?

 

If database do something like this:

<table>
<?php
$result = mysql_query("SELECT name FROM clans");
while($row = mysql_fetch_array($result)){
echo "<tr><td>'$row['name']'</td></tr>";
}
?>
</table>

 

If in array use a foreach loop...

Here is my code where I pull it up from the db in an array:

$sql="SELECT `clan_name`,`wins`,`losses`,`message`,`clan_id`,`link` FROM `bhdsingle`  ORDER BY `wins` DESC";

$res=mysql_query($sql) or die(mysqll_error());

while ($list = mysql_fetch_array($res)) {

$clan_name = $list["clan_name"];

$wins = $list["wins"];

$losses = $list["losses"];

$message =$list["message"];

$clan_id = $list["clan_id"];

$link = $list["link"]; 

     

  }

 

$sql="SELECT `clan_name`,`wins`,`losses`,`message`,`clan_id`,`link` FROM `bhdsingle`  ORDER BY `wins` DESC";

 

$res=mysql_query($sql) or die(mysqll_error());

 

while ($row = mysql_fetch_array($res))

{

$list = "<table>";

$list .= "<tr>";

$list .= "<th>Clan Name</th>";

$list .= "<td>".$row["clan_name"]."</td>";

$list .= "<tr>";

$list .= "</table>";

 

echo( $list );

}

 

Add more columns etc to suit when you know how you want table displayed

thank you for pointing me in the right direction. Definitely going to have to fiddle with it for awhile. I have 5-6 items to be used as table data.

  So if I wanted to display "clanname"-"wins"-"losses" I would need to set up a new while statement for each set of table data.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.