0

I'm using the HTML attribute dataset with a select list.

<input type="text" name="productcode[]" id="productcode" class="productcode" list="products">
<datalist id="products">
    <?php

     $query=mysql_query(" 
     SELECT * FROM dbProducts ORDER BY product_name"); 
     while($entry=mysql_fetch_array($query)) 
            {
              echo '<option value="' . $entry['product_code']'">' . $entry['product_name'] . '</option>';  
            } ?>
</datalist>

As you can see the option value is different to the displayed text. If I was using <select> I could pass the value into a form whilst only showing the text I want. Is there a way of doing this with <datalist>? At the moment my form returns the input type with the product_code and product_name values.

tomantford
  • 182
  • 22

1 Answers1

0

Have you tried this?

<?php
$query=mysql_query(" 
SELECT * FROM dbProducts ORDER BY product_name"); 
while($entry=mysql_fetch_array($query)) 
{
$productcode = $entry['product_code'];
$productname = $entry['product_name'];

echo "<option value=$productcode>$productname</option>";  
} 
?>

When you are writing html in php you can't use "" inside a echo.

niiicolai
  • 73
  • 2
  • 12
  • Thanks, the problem isn't with the mysql query - that all works fine. The problem is using a datalist in the same way as a select input and showing a string but having the form post a separate value – tomantford Oct 03 '14 at 12:45