[Solved] How to fetch all data from database? [closed]


DO NOT USE MYSQL, instead use MySQLi as MySQL is DEPRECATED .

But:

$tid=$_SESSION['id'];
 $a=mysql_query("select * from tbl_curriculum_sched where TEACHER_ID='$tid'") or die("$ a error : ".mysql_error());          

 while($ad=mysql_fetch_array($a)){
$sql= mysql_query("SELECT * from enrolled where CURRICULUM_SCHED_ID='$ad[0]'") or die("inner while: ".mysqli_error());
...

To those of you commenting and comlaining that the OP should be using $a, rather than $ad – no, this is not the case – as the while statement will output content into the $ad variable as both named and numerical keys.

Also: The database connection needs to be declared.

Also: session_start() needs to be declared.

If the $ad[0] specifically does not have a value and no mysql_error() has been thrown then look into using mysql_fetch_row as settings in PHP ini mean that possibly the numerical keying of data from the MySQL table is not kept, and data is possibly only stored by name, which is better way to use the data all round.

Try and avoid using SELECT * too.

1

solved How to fetch all data from database? [closed]