Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: HTML PHP
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 1:23am
Edited 6-Oct-12 2:25am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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']."
";
    next($val);
  } 
}
?>
 
See if this works. All the best...Smile | :)
  Permalink  
Comments
Sourav Sarkar-SS at 6-Oct-12 14:41pm
   
Hey thanks!
Patrick Wanjau at 6-Oct-12 14:45pm
   
you're welcome
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
$diet= $_POST["diet"];
Refer: PHP HTML Form Example[^]
  Permalink  
Comments
Sourav Sarkar-SS at 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 at 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 at 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 at 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 at 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 at 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 at 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
0 OriginalGriff 495
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 200
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 6 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100