Click here to Skip to main content
Sign Up to vote bad
good
See more: HTMLPHP
I have a control in html look like this.
 
 <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
     $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.
$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 6-Oct-12 0:23am
Edited 6-Oct-12 1:25am


2 solutions

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...Smile | :)
  Permalink  
Comments
Sourav Sarkar-SS - 6-Oct-12 14:41pm
Hey thanks!
Patrick Wanjau - 6-Oct-12 14:45pm
you're welcome
Try:
$diet= $_POST["diet"];
Refer: PHP HTML Form Example[^]
  Permalink  
Comments
Sourav Sarkar-SS - 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
Sourav Sarkar-SS - 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.
Sourav Sarkar-SS - 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.
Sourav Sarkar-SS - 6-Oct-12 14:41pm
Me too Its a feeling like in hell by knowing you and talking with you. I don't need any of your f***ing suggestion any more. Don't answer my question any more. stay out of these, If you don't know be happy with .Net what you know
Sourav Sarkar-SS - 6-Oct-12 11:00am
now can you please delete your answer as its a wrong answer and that make my question unanswered and let others to answer my question.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 6,889
1 Prasad_Kulkarni 3,671
2 OriginalGriff 3,359
3 _Amy 3,312
4 CPallini 2,925


Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 6 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid