lordtrini Posted April 9, 2010 Share Posted April 9, 2010 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/198176-php-query-results-in-a-table/ Share on other sites More sharing options...
the182guy Posted April 9, 2010 Share Posted April 9, 2010 The headings are repeating because they are inside the while loop. What code are you using that's causing an error with the border property? Quote Link to comment https://forums.phpfreaks.com/topic/198176-php-query-results-in-a-table/#findComment-1039803 Share on other sites More sharing options...
ddubs Posted April 9, 2010 Share Posted April 9, 2010 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;'>"; Quote Link to comment https://forums.phpfreaks.com/topic/198176-php-query-results-in-a-table/#findComment-1039806 Share on other sites More sharing options...
the182guy Posted April 9, 2010 Share Posted April 9, 2010 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/198176-php-query-results-in-a-table/#findComment-1039812 Share on other sites More sharing options...
Domcsore Posted April 9, 2010 Share Posted April 9, 2010 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/198176-php-query-results-in-a-table/#findComment-1039816 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.