Page 1 of 1

incomplete query results

Posted: Sun Feb 12, 2006 4:19 pm
by tr33b1rd
I am having trouble with a form dropdown populated with a MySQL query in PHP. It is not returning a complete list of results. If I run the same SQL query in PHP MyAdmin, I get the correct results, so it must be my PHP code (or server config). Here is the code for my dropdown:

Code: Select all

<select name="search_end_style">
 <?php
$sqlselect_end_style = "SELECT DISTINCT end_style FROM products WHERE search_categories = 'IDLE CABLE' ORDER BY end_style";
 $sqlresult_end_style = mysql_query($sqlselect_end_style);
 $array_end_style = mysql_fetch_array($sqlresult_end_style);
 while($array_end_style = mysql_fetch_array($sqlresult_end_style)){
  $list_end_style = $array_end_style['end_style'];
  $value_end_style = $array_end_style['end_style'];
  $option_end_style = "<option value=".$value_end_style.">".$list_end_style."</option></br>";
  print $option_end_style;
  }
   ?>
</select>
If I remove DISTINCT from the query, I get all of the results, however I need to remove duplicate records from the array.

Also, If I remove the WHERE clause, I get all of the records in the column, however I do need to leave the where clause there.

If I sort the order different ways (ASC, DESC) I get a different set of results. There are only 2 values in the 'end_style'. If I sort by ASC I get one value. If I sort by DESC I get the other value.

I appears that my PHP script is not making the full query, like it is being cut off half way through and returning the first half of the results. Is there a reason for this in my code? Or possibly the php.ini file?

Can I remove DISTINCT from the query and remove the duplicate values in PHP? Doing this would solve my problem. I have tried to use array_unique(), but I cannot get it to work.

Posted: Sun Feb 12, 2006 4:21 pm
by feyd
remove the line with mysql_fetch_array() immediately following mysql_query(). You only need it once in your script (apart of the while loop)