Tables in a PHP script

Started by Ardenn, December 09, 2003, 04:22:01 PM

Previous topic - Next topic

Ardenn

Here is the code Im working with.

<?
//This script displays all data on the page from
//the selected database table

//MySQL Variables. Edit where necessary

$host = "localhost";
$login_name = "root";
$password = "";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
MySQL_select_db("songs") or die("Could not select database");

//Selects all data from table

$result = MySQL_query("SELECT * FROM songdata ORDER BY level");

ECHO "<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"0\">
  <td>Level</td>
  <td>Name</td>
  <td>Description</td>
</table>";


//Loop to print each line of database
While( $rows = MySQL_fetch_array($result) ) {

$name = $rows['Name'];
$level = $rows['Level'];
$description = $rows['Description'];
//How the text looks on the screen

ECHO "<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"0\">
  <td>$level</td>
  <td>$name</td>
  <td>$description</td>
</table>";

}


?>


What I would like to do is make the table "format" holding the description to match the table format holding my data.  I dont really know how to do that.  Does anyone have a suggestion?
Ardenn // Traxxus
http://www.twinwand.com
D&D Play by Post Community Looking for Players and DM's

Tyris


<?php
//This script displays all data on the page from
//the selected database table

//MySQL Variables. Edit where necessary

$host "localhost";
$login_name "root";
$password "";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
MySQL_select_db("songs") or die("Could not select database");

//Selects all data from table

$result MySQL_query("SELECT * FROM songdata ORDER BY level");

echo 
"<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"0\">
<tr>
  <td>Level</td>
  <td>Name</td>
  <td>Description</td>
</tr>"
;


//Loop to print each line of database
While( $rows MySQL_fetch_array($result) ) {

$name $rows['Name'];
$level $rows['Level'];
$description $rows['Description'];
//How the text looks on the screen

echo "<tr>
  <td>
$level</td>
  <td>
$name</td>
  <td>
$description</td>
</tr>"
;

}
echo 
"</table>";
?>



That should do it... you didnt have <tr> tags...
by adding them, and making it all one table... they will all format the way you want I think...

Advertisement: