kaydrae kaydrae - 1 year ago 64
SQL Question

Information not showing up my MySQL Database

I'm trying to open a new php page from the sNumber and display the data from the student table on student profile page from the sNumber. But I can't retrieve the data, it goes right to the error. Any help will be appreciated. Thanks


<div class="memtable">
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
echo '<div class="pagination"><ul>';
if ($total_pages > 1) {
echo paginate($reload, $show_page, $total_pages);
echo "</ul></div>";
// display data in table
echo "<table class='table table-bordered'>";
echo "<thead><tr><th>Last Name</th> <th>First Name</th> <th>School</th> <th>Snumber</th></tr></thead>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++) {
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) {

// echo out the contents of each row into a table
$lastName = "<a href = 'studentprofile.php?id= " .mysql_result($result, $i, 'sNumber'). "'>" . mysql_result($result, $i, 'lastName') . "</a>";

echo "<tr " . $cls . ">";
echo '<td>' . $lastName . '</td>';
echo '<td>' . mysql_result($result, $i, 'firstName') . '</td>';
echo '<td>' . mysql_result($result, $i, 'school') . '</td>';
echo '<td>' . mysql_result($result, $i, 'sNumber') . '</td>';
echo "</tr>";
// close table>
echo "</table>";
// pagination




if ( isset( $_GET[ "sNumber" ] ) )
$student_sNumber = $_GET['sNumber'];

$getStudentInfo = " SELECT sNumber FROM student WHERE student.sNumber = " . $student_sNumber;

<!DOCTYPE html>
<link href="css/style.css" rel="stylesheet" type="text/css">
<div class="transoverlay">

if ($result = mysql_query($getStudentInfo)) {
/* fetch associative array */
while ($row = mysql_fetch_assoc($result)) {

echo "<h1 class='tv'>" . $row["sNumber"]. ", ". $row['firstName']."</h1>";



echo "<div class='tv'>Student Data could not be listed. </div>";


<hr color="#1a1a1a">


<?php include('footer.php');?>

Answer Source

the url uses id but you checking for sNumber change one of those

you need to quote student number in the query as its a string

$getStudentInfo = "SELECT sNumber FROM student WHERE student.sNumber ='". $student_sNumber."'";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download