Jump to content

Recommended Posts

I am trying to display the results of a query in the form of a table. this it the PHP that i am using below. The problem is that the headings of the table repeats. I really don't want that...

 

I am also trying to get a border around the cells of the table, but i get an error when i add table properties

 

Can someone help me please.

 

<?php

 

if ( isset( $_GET['id'] ) )

{

 

$query = "SELECT * FROM schedule WHERE course_id = '". $_GET['id'] ."' ORDER BY indexx ASC";

 

$numresults=mysql_query($query);

$numrows=mysql_num_rows($numresults);

 

 

if ($numrows == 0)

{

echo "This course does not have a set schedule. ";

 

}

 

$q .= " limit $s,$limit";

$result = mysql_query($query) or die("Couldn't execute query");

 

while ($row= mysql_fetch_array($result))

{

$indexx = $row["indexx"];

$semester = $row["semester"];

$day = $row["day"];

$time = $row["time"];

$instructor = $row["instructor"];

$location = $row["location"];

 

 

echo "<table>";

echo "<tr>";

echo " <td>Index</td>";

echo "<td>Semester</td>";

echo "<td>Day</td>";

echo "<td>Time</td>";

echo "<td>Instructor</td>";

echo "<td>Location</td>";

echo "</tr>";

echo "<tr>";

echo "<td>$indexx</td>";

echo "<td> $semester</td>";

echo "<td>$day</td>";

echo "<td>$time</td>";

echo "<td>$instructor</td>";

echo "<td>$location</td>";

echo "</tr>";

echo"</table>";

 

 

 

 

$count++ ;

 

} // end WHILE

 

echo "<br/>End test link<br/>";

} // end IF

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/198176-php-query-results-in-a-table/
Share on other sites

if you want to add a style property directly to:

echo "<table>";

 

then you need to escape the quotes or use single quotes:

echo "<table style=\"border:1px solid #000;\">";

or

echo "<table style='border:1px solid #000;'>";

 

You're right about escaping the quotes but the CSS you used there will only put a border around the 4 sides of the table. I think OP wants to put a border around each cell in which case he'd need to do something like

 

echo "<table border=1>";

Try this:

 


<?php

if ( isset( $_GET['id'] ) )
{

$query = "SELECT * FROM schedule WHERE course_id = '". $_GET['id'] ."' ORDER BY indexx ASC";

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);


if ($numrows == 0)
{
echo "This course does not have a set schedule. ";

}

$q .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

echo "<table border='1'>";
echo "<tr>";
echo " <td>Index</td>";
echo "<td>Semester</td>";
echo "<td>Day</td>";
echo "<td>Time</td>";
echo "<td>Instructor</td>";
echo "<td>Location</td>";
echo "</tr>";

while ($row= mysql_fetch_array($result))
{
$indexx = $row["indexx"];
$semester = $row["semester"];
$day = $row["day"];
$time = $row["time"];
$instructor = $row["instructor"];
$location = $row["location"];

echo "<tr>";
echo "<td>$indexx</td>";
echo "<td> $semester</td>";
echo "<td>$day</td>";
echo "<td>$time</td>";
echo "<td>$instructor</td>";
echo "<td>$location</td>";
echo "</tr>";




$count++ ;

} // end WHILE

echo"</table>";

echo "<br/>End test link<br/>";
} // end IF


?>

 

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.