| | |
How to assign Menu lists' values to variables?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2009
Posts: 4
Reputation:
Solved Threads: 0
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.
what should i do in order to assign first one's value to $StudentNumber and second one's $EXAM
1st one which brings "Student Numbers" rows from its column in selected class table.
php Syntax (Toggle Plain Text)
$query="SELECT StudentNumber,Student_id FROM $CC"; $result = mysql_query ($query); echo "<select name=\"STUDENT\" value=''>Student Number</option>"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[Student_id]>$nt[StudentNumber]</option>"; } echo "</select>"; and second brings field names (Quizzez and midterms etc..) from that selected class table (btw it piece gives two errors 1-Warning: mysql_list_fields() [function.mysql-list-fields]: Unable to save MySQL query result in 2- Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource $fields = mysql_list_fields("Courses", "$CC", $link_id2); $columns = mysql_num_fields($fields); echo "<select name=\"EXAM\">"; for ($i = 4; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } 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.
To assign the values of the option list you are going to want to use a php echo inside the value quotes:
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.
PHP Syntax (Toggle Plain Text)
option value="<?php echo $StudentNumber;?>" 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.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Foreign Key is different than primary key
- Next Thread: How can one upload multiple files with php?
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





