943,832 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1194
  • PHP RSS
Jan 3rd, 2009
0

How to assign Menu lists' values to variables?

Expand Post »
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.

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SOB224 is offline Offline
4 posts
since Jan 2009
Jan 3rd, 2009
0

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

To assign the values of the option list you are going to want to use a php echo inside the value quotes:
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Light Poster
DiGSGRL is offline Offline
45 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Foreign Key is different than primary key
Next Thread in PHP Forum Timeline: How can one upload multiple files with php?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC