Note that there are some explanatory texts on larger screens.

plurals
  1. POphp duplicate keys in an array for a dropdown list
    text
    copied!<p>I need to show duplicate values from a mysql table in a dropdown list. I was not able to do this because arrays cannot have duplicate keys. But I have found a function which can take duplicate keys.</p> <p>I need someone's help who can guide me to put dropdown list values into this function:</p> <p>dropdownlist:</p> <pre><code>$dc=mysql_query("SELECT * FROM ECR_CBDC WHERE Prod_desc='$product' AND Ac_code='$custcode' AND Ecr_No=0 AND usr='$user' AND Cylno!='' ORDER BY Cylno ASC"); $num_rows = mysql_num_rows($dc); $fill_from_array = array(); /* as "value"=&gt;"option" */ for($i = 1; $i &lt;= $num_rows; $i++) { $row = mysql_fetch_array($dc); $fill_from_array[$row['Cylno']] = $row['Cylno']; } </code></pre> <p>function to have duplicate keys:</p> <pre><code>&lt;?php function array_combine_($keys, $values) { $result = array(); foreach ($keys as $i =&gt; $k) { $result[$k][] = $values[$i]; } array_walk($result, create_function('&amp;$v', '$v = (count($v) == 1)? array_pop($v): $v;')); return $result; } print_r(array_combine_(Array('2','2','3'), Array(2,2,3))); ?&gt; </code></pre> <p>Table ECR_CBDC has following values for a column Cylno: 10 20 20 30 40 50 50</p> <p>When I put the above values into an array - fill_from_array, the values would be like this:</p> <pre><code>10 =&gt; 10 20 =&gt; 20 30 =&gt; 30 40 =&gt; 40 50 =&gt; 50 </code></pre> <p>What I need in the array is :</p> <pre><code>10 =&gt; 10 20 =&gt; 20 20 =&gt; 20 30 =&gt; 30 40 =&gt; 40 50 =&gt; 50 50 =&gt; 50 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload