...

View Full Version : Question about returning unique rows



Bar2aYunie
06-22-2010, 02:50 PM
Hello,

I've got a question about returning unique rows with php from the database.

Lemme first place my code:



$sizecat=mysql_real_escape_string($_GET[sizecat]);
$finalsize=$_GET[finalsize];
$color=$_GET[color];
$material=$_GET[material];
$size=$_GET[size];

$finalQuery=mysql_query("SELECT DISTINCT thumb_size, size, totalsize, Info, material, thumb_material, finalsize, color FROM `Folders` WHERE `sizecat`='{$sizecat}' AND `finalsize`='{$finalsize}' AND `color`='{$color}' AND `material`='{$material}';");

This part completely works and I got unique rows (no double entries are shown). However, the query returns four rows, instead of only one. Therefore, I need to add this:


AND `size`='{$size}'

in the select query at the end. But then the query doesn't return any row anymore.... If I do the same in sql database, I get the one row I am looking for (with the added variables of course). Now this is part of a switch and this is the final step of 5 total steps. The first four variables (sizecat, finalsize, color and material) are called during every step starting with the first one and adding one with every next step.

So it seems logically that php can recall the selected variables. The last one that I need to add isn't called anywhere before, except for the first step. If I call these at the other steps, I don't get one row as a result.... I get more results shown.

The thing is, that there are more sizes, but only one color. So during the third step (which is color), I only want one result.... But if I add the last part to get the size, I get more results are there are three different sizes and only one color.

But if I don't add the size part there, php doesb't know which size it must return and thus the query returns empty.

Does anybody know how I can fix this? thx in advace!! :D

Fumigator
06-22-2010, 03:53 PM
Does your call to mysql_query() ever fail? That is to say, does it every return FALSE?

Bar2aYunie
06-22-2010, 06:41 PM
No it works. Though only sometimes it is empty (no results found). But it completely works. Why?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum