Hi guys, i need some help with a too complaicated query for my little brain.
I have the following query:
$query = "
(SELECT pic, text, main, gr, min(nr) AS nr FROM info WHERE (gr>0) AND (stl LIKE '$stl') AND ((quantity >= 0 and utg!='J') or (quantity > 0 and utg ='J')) GROUP BY gr)
UNION
(SELECT pic, text, main, gr, nr FROM info WHERE (gr=0) AND (stl LIKE '$stl') AND ((quantity >= 0 and utg!='J') or (quantity > 0 and utg ='J')))
UNION
(SELECT pic, text, main, gr, min(nr) AS nr FROM info WHERE (gr>0) AND (enh LIKE '$stl') AND ((quantity >= 0 and utg!='J') or (quantity > 0 and utg ='J')) GROUP BY gr)
UNION
(SELECT pic, text, main, gr, nr FROM info WHERE (gr=0) AND (enh LIKE '$stl') AND ((quantity >= 0 and utg!='J') or (quantity > 0 and utg ='J')))
ORDER BY nr";
which works perfectly, the prob is that the system has gotten more complicated with the time and $stl (which is a result from one other query) now is actually more results. So if before $stl was = 1, now its also =2 and =3 and i need all that selected by the query.
I thought of making a string of the results like:
$rowCount = mysql_num_rows($resultpage);
if ($rowCount > 0) {
$row = mysql_fetch_array($resultpage);
$stlString = 'stl LIKE ' . $row['stl'];
for ($i = 1; $i < $rowCount; $i++) {
$row = mysql_fetch_array($resultpage);
$stlString .= ' OR stl LIKE ' . $row['stl'];
}
}
which will return *stl like 1 or stl like 2 or slt like 3... etc* (which is still incorrect, missing the () around) but i don't know the right syntax/way to insert that string into the query (or build more to the string so it returns the whole query and what to do after), instead of just having (stl LIKE '$stl') .
I also thought of simply having some for-loop wrapping the whole big query+code after it, so it gets one query for each $stl, but the prob is that i need only one query because i need the numrows of that query.
Highly appreciate any help!