Topic: Problem Fetching Data

Hi, I wondered if someone would be able to help. I am trying to set up a timetable site for my students, where they can enter their username and then retrieve their timetable.  We work on a bi-weekly timetable of 5 lessons per day (e.g. 1Mon1 would be Week 1, Monday, Lesson 1, 1Mon2 would be lesson 2 etc).  I have the data all in my database, but I am having problems getting the data out. The code I have below is how far I have gotten but I just keep getting a blank screen.    I am very very new to PHP and any help would be massively appreciated.


<?php
$userName = '07cnunn';
$host = "localhost";
$db_name = "conyerst_timetables";
$user = "******";
$pass = "*****!";
 
mysql_connect($host, $user, $pass);
mysql_select_db($db_name);


$sql=("SELECT core.UserID, wstt.Period, wstt.Lesson, wstt.Staff, wstt.Room\n FROM wstt INNER JOIN core ON wstt.Adno = core.Adno\n WHERE core.UserID=core.UserID='%s'", mysql_real_escape_string($userName));



$result = mysql_query($sql);


if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

while ($row = mysql_fetch_array($result)) 
{ 

    $field1= $row['core.UserID'];
    $field2= $row['wstt.Period'];
    $field3= $row['wstt.Staff'];
    $field4= $row['wstt.Room'];
    
    echo "$field1<br>";
    echo "$field2<br>"; 
    echo "$field3<br>"; 
    echo "$field4<p>"; 
}

mysql_free_result($result);
?>

Last edited by greensparrow (November 28, 2011 14:50)

Thumbs up