Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir,

i want to fetch data from database i bind it to dropdown list of html .

below is my HTML code

HTML
<table>
  <tbody>
    <tr>
      <td>
        <div id="container2">
          <input list="medicinename1" 
                    placeholder="type word" 
                    autocomplete='off' 
                    name='pname' 
                    id='pname' value=''
                    style="width:100px;height:25px" />
          <datalist id="medicinename1">

          </datalist>
        </div>
      </td>
    </tr>
  </tbody>
</table>


this is my php code inside datalist

PHP
$q1=mysql_query("SELECT kismispurchase.km_id, kismispurchase.kpm_id,kismispurchase.lot_no as lot_no, kismispurchasemaster.Sdate as sdate FROM kismispurchase inner join kismispurchasemaster on kismispurchasemaster.kpm_id=kismispurchase.kpm_id where kismispurchase.availableqty!=0");
while($res=mysql_fetch_row($q1))
{
    $x=$res['lot_no'];
    $x2=$res['sdate'];
    echo "&lt;option value='$x1'&gt;$x&lt;/option&gt;;";
}


In value i want to put lot_no and sdate, how it is possible to bind two values.
please help mi...
Posted
Updated 6-Jul-14 19:59pm
v7
Comments
George Jonsson 7-Jul-14 1:27am    
Can't you just concatenate the two values into a third variable and bind that variable?
Rajkumar_007 7-Jul-14 1:38am    
$q1=mysql_query("SELECT kismispurchase.km_id, kismispurchase.kpm_id,kismispurchase.lot_no as lot_no, kismispurchasemaster.Sdate as sdate FROM kismispurchase inner join kismispurchasemaster on kismispurchasemaster.kpm_id=kismispurchase.kpm_id where kismispurchase.availableqty!=0");
while($res=mysql_fetch_row($q1))
{
$x=$res['lot_no'];
$x2=$res['sdate'];
echo "<option value='$x1'>$x</option>;";
}
this is my select query to bind value in datalist
Mohibur Rashid 7-Jul-14 1:30am    
Question is not clear.
George Jonsson 7-Jul-14 2:00am    
I reformatted the HTML part. It should be a bit clearer now.

1 solution

Try this:
XML
<?php
    // your sql statement
?>

<input list="medicinename1" name="pname">
<datalist id="medicinename1">

<?php
     while($res=mysql_fetch_row($q1))
    {
         $x=$res['lot_no'];
         $x2=$res['sdate'];
         $concat = $x.' '.$2;
         echo  '<option value="'.$concat.'">';
    }
?>

</datalist>
 
Share this answer
 

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