Cannot display item from database from specific user
Posted: Mon Apr 04, 2011 1:35 pm
I'm new to php,and i met some problem when displaying item from database. When user log in, i can retrieve and display username from database in page, but it failed to display when I try to retrieve and display relevant item related to the user at the same page...anyone can help???
/*1st: CAN NOT display item when assigned lecID=$id, which retrieve from input(log in)*/
<?php
include 'Connections/myconnection.php';
mysql_select_db($database_myconnection, $myconnection)
or die("Unable to connect to MySQL");
$query = "SELECT subCode FROM lecturer WHERE lecID=$id LIMIT 1";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
echo "{$row['subCode']}<br>" ;
}
?>
/*2nd: CAN display when assigned lecID=1133, which specified the user ID*/
<?php
include 'Connections/myconnection.php';
mysql_select_db($database_myconnection, $myconnection)
or die("Unable to connect to MySQL");
$query = "SELECT subCode FROM lecturer WHERE lecID=1133 LIMIT 1";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
echo "{$row['subCode']}<br>" ;
}
?>