How to assign Menu lists' values to variables?

Reply

Join Date: Jan 2009
Posts: 4
Reputation: SOB224 is an unknown quantity at this point 
Solved Threads: 0
SOB224 SOB224 is offline Offline
Newbie Poster

How to assign Menu lists' values to variables?

 
0
  #1
Jan 3rd, 2009
I am trying to keep two menu lists' option in variables but i dont know whether to use "selected" or "select name" to assign value

1st one which brings "Student Numbers" rows from its column in selected class table.

  1. $query="SELECT StudentNumber,Student_id FROM $CC";
  2. $result = mysql_query ($query);
  3. echo "<select name=\"STUDENT\" value=''>Student Number</option>";
  4.  
  5. while($nt=mysql_fetch_array($result)){
  6. echo "<option value=$nt[Student_id]>$nt[StudentNumber]</option>";
  7. }
  8. echo "</select>";
  9.  
  10.  
  11. and second brings field names (Quizzez and midterms etc..) from that selected class table (btw it piece gives two errors
  12. 1-Warning: mysql_list_fields() [function.mysql-list-fields]: Unable to save MySQL query result in
  13. 2- Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource
  14.  
  15. $fields = mysql_list_fields("Courses", "$CC", $link_id2);
  16. $columns = mysql_num_fields($fields);
  17. echo "<select name=\"EXAM\">";
  18. for ($i = 4; $i < $columns; $i++) {
  19. echo "<option value=$i>";
  20. echo mysql_field_name($fields, $i);
  21. }
  22. echo "</select>";


what should i do in order to assign first one's value to $StudentNumber and second one's $EXAM
Last edited by peter_budo; Jan 6th, 2009 at 2:01 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 45
Reputation: DiGSGRL is an unknown quantity at this point 
Solved Threads: 4
DiGSGRL's Avatar
DiGSGRL DiGSGRL is offline Offline
Light Poster

Re: How to assign Menu lists' values to variables?

 
0
  #2
Jan 3rd, 2009
To assign the values of the option list you are going to want to use a php echo inside the value quotes:
  1. option value="<?php echo $StudentNumber;?>"
  2. option value="<?php echo $Exam;?>"

When you get the error "Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource", this usually means that your query is wrong so it is not returning any results. Which means your mysql_list_fields is also wrong. The php manual also says that this function is deprecated and shows an alternative to using it. Here is the link to the php manual for mysql_list_fields:
http://us.php.net/mysql_list_fields

Anyways I hope this was helpful.
A little clarification goes a long way.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC