0

Hi users of Stack Overflow,

I am facing a issue where my SQL data won't display properly and I am not sure on how to fix this problem. I only see the print section with no appropriate data.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <link rel="stylesheet" href="css/default.css" type="text/css" />
 <link rel="stylesheet" href="css/timetable.css" type="text/css" />
<title>Timetable Information</title>
</head>
<body>


<div id="header"></div>


<ul id="NavigationList">
<li><a href="Index.php">Index</a></li>
<li><a href="ModuleInfo.php">Module Info</a></li>
<li><a href="ModuleSearch.php">Module Search</a></li>
<li><a href="Timetable.php">Timetable Search</a></li>

</ul>
<p>
<p>Please select a school from the drop-down list.</p>

   <?php
require('json.php');
error_reporting(E_ALL);
$connection = mysql_connect('localhost', 'root','') or
    die("Could not connect: " . mysql_error());
mysql_select_db("timetable") or die("No such database");
$sql = sprintf("
  SELECT id,day,start,module
    FROM event JOIN teaches ON (event.id=teaches.event)
   WHERE staff='%s'", mysql_real_escape_string($_REQUEST['staff']));
$result = mysql_query($sql)
  or die(mysql_error());
while ($row = mysql_fetch_array($result)){
    print "<div>$row[id] $row[module] $row[day] $row[start]</div>\n";
}
?>
</p>
<div id="Footer">
            <p id="FooterText">Copyright &copy; 2012 .<br     />All     rights reserved.</p>    
            </div>
</body>
</html>
15
  • 3
    mysql_connect('localhost', 'root','') - nice nice ) Commented Apr 23, 2012 at 11:25
  • should there be quotes around the field names? Commented Apr 23, 2012 at 11:27
  • Please remove error reporting and post the error you will get. So that we can able to debug it more accurately. Commented Apr 23, 2012 at 11:28
  • @RohitKumarChoudhary I am recieving no error, All I get displayed is {$row['id']} {$row['module']} {$row['day']} {$row['start']}\n"; } ?> Commented Apr 23, 2012 at 11:32
  • Try to print just the SQL query and run it to see if it even shows any data there Commented Apr 23, 2012 at 11:33

4 Answers 4

1

Use:

print "<div>{$row['id']} {$row['module']} {$row['day']} {$row['start']}</div>\n";

Instead of:

print "<div>$row[id] $row[module] $row[day] $row[start]</div>\n";
Sign up to request clarification or add additional context in comments.

2 Comments

I have changed it, but it only displays the line and not the data within the table.
Are you sure that mysql_num_rows($result) returns a value more than 0?
1
while ($row = mysql_fetch_assoc($result)) { 
    $symbol= $row['Symbol'];
    $date= $row['Date']; 
    $avgprice= $row['avg_price']; 
    $var4 = $row['field4']
    ."<br>";


    echo "<tr>
        <td >".$symbol."</td>
        <td >".$date."</td>
        <td >".$avgprice."</td>
        <td >".$var4."</td>

    </tr>";

Comments

0

Try This

while ($row = mysql_fetch_array($result)){
echo "<div>".$row['id'];
echo $row['module'];
echo $row['day'];
echo $row['start'];
echo "</div>";
}

Instead of: print "$row[id] $row[module] $row[day] $row[start]\n";

2 Comments

Displays this - ".$row['id']; echo $row['module']; echo $row['day']; echo $row['start']; echo ""; } ?>
try this$sql = "SELECT id,day,start,module FROM event JOIN teaches ON (event.id=teaches.event) WHERE staff='%s'", mysql_real_escape_string($_REQUEST['staff']); $result = mysql_query($sql)
0

try something like this

print "<div>".$row[id]. $row[module]. $row[day]. $row[start]."</div>\n";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.