Connecting Tech Pros Worldwide Forums | Help | Site Map

values from database to array

Member
 
Join Date: Nov 2008
Posts: 41
#1: Sep 15 '09
am trying to get the list of students in a class into an array and echo it one after another in a read only textbox so the lecturer can enter scores against each registration number i have this:
Expand|Select|Wrap|Line Numbers
  1. $my_query=mysql_query(select * from table where class='$class'");
  2. while($row=mysql_fetch_assoc($my_query)){
  3.       $regno[] .=$row['regno'];
  4.       $count++;
  5. }
  6. echo $count;
  7. for($i=0; $i<=$count; i++){
  8. echo $regno['$i'];
  9. }
  10.  
the "echo $count " shows the number of students in the class but the $regno is just empty pls help

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#2: Sep 15 '09

re: values from database to array


remove the dot operator.
Member
 
Join Date: Nov 2008
Posts: 41
#3: Sep 15 '09

re: values from database to array


thanks but no luck with that either
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#4: Sep 15 '09

re: values from database to array


then do a var_dump() on $regno.
Member
 
Join Date: Nov 2008
Posts: 41
#5: Sep 15 '09

re: values from database to array


its giving me this
Expand|Select|Wrap|Line Numbers
  1. array(3) { [0]=>  NULL [1]=>  NULL [2]=>  NULL }
  2.  
but there are values in the database (3 records). could it be the fetch_assoc?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#6: Sep 15 '09

re: values from database to array


maybe the DB field name is a bit different… there could be many reasons.
Reply