Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a control in html look like this.

PHP
<select  name='diet' class='inputbox'>
         <option value=''>Select one</option>
         <option value='VEG' >VEG</option>
         <option value='Non-Veg' >Non-Veg</option>
         <option value='Eggiterian' >Eggiterian</option>
       </select>


Now through PHP I stored the data in MYSQL.
Now at the time of retrieve, I execute a query.

Like this
PHP
$qry="SELECT diet FROM tablename where id=" .$id ;
$res=mysql_query($qry);
while($val = mysql_fetch_array($res))
{
 //please help me here to select the above control's value
}


Database can store only VEG, non-VEG, or Eggiterian value.
at the time of retrieval process it should select the value present in the query result.

Please help me.

I want to select the value of the combo box by the value of my query result.
PHP
$qry="SELECT diet FROM tablename where id=" .$id ; 
$res=mysql_query($qry); 
while($val = mysql_fetch_array($res)) 
{ 
echo " <select name='diet' class='inputbox'>
 <option value=''>Select one</option> 
<option value='VEG' >VEG</option>
 <option value='Non-Veg' >Non-Veg</option> 
<option value='Eggiterian' >Eggiterian</option>
 </select>"; 
} 

I need to select the option of combo box with the value present in my database table. Value will be either veg or non-veg or eggiterian. please help
Posted
Updated 6-Oct-12 1:25am
v2

PHP
if(isset($_REQUEST['diet'])){
  $id = $_REQUEST['diet'];
  $res = mysql_query("SELECT diet FROM tablename where id=".$id);
  while($val = mysql_fetch_array($res)){
    echo $val['diet']."<br />";
    next($val);
  } 
}
?>


See if this works. All the best...:-)
 
Share this answer
 
Comments
[no name] 6-Oct-12 14:41pm    
Hey thanks!
Patrick Wanjau 6-Oct-12 14:45pm    
you're welcome
Try:
PHP
$diet= $_POST["diet"];

Refer: PHP HTML Form Example[^]
 
Share this answer
 
Comments
[no name] 6-Oct-12 7:04am    
no dear
you didn't understood my question
I want to select the value of the combo box by the value of my query result.
$qry="SELECT diet FROM tablename where id=" .$id ;
$res=mysql_query($qry);
while($val = mysql_fetch_array($res))
{
echo " <select name='diet' class='inputbox'>
<option value=''>Select one</option>
<option value='VEG' >VEG</option>
<option value='Non-Veg' >Non-Veg</option>
<option value='Eggiterian' >Eggiterian</option>
</select>";
}

I need to select the option of combo box with the value present in my database table. Value will be either veg or non-veg or eggiterian.

please help
[no name] 6-Oct-12 9:24am    
this is very bad
giving wrong answer
and not replying after that
It pretend others to give the answer
you are a ..........
Sandeep Mewara 6-Oct-12 10:21am    
You fail to post proper question and then try to abuse later.

Thanks, but you are not welcome.
[no name] 6-Oct-12 10:58am    
first what is wrong in my question?
second when I replied why you are not replied?
third you are not a judge who decide its a proper question or not, if you didn't understood the question then can ask for clarification or leave for others to answer
Sandeep Mewara 6-Oct-12 11:29am    
what is wrong in my question?
Answer was based on what you asked. Now, you say it is not so and try to abuse. Forget it.

when I replied why you are not replied?
I will not sit whole day for you to reply back

you are not a judge who decide its a proper question or not,
Everyone can judge that so can I. Just like you can judge an answer is right or not and downvoted me. So, don't try to tell me what I can do and what I cannot.

Don't expect any more comment from me. It was not nice knowing you so, have a nice day. Bye.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900