Tombie Posted May 3, 2010 Share Posted May 3, 2010 ok so in php i have a query and store it in a results variable, how do i then perform a query on the results of that first query i did? assuming its very basic but for the life of me im having a mental block Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/ Share on other sites More sharing options...
ChemicalBliss Posted May 3, 2010 Share Posted May 3, 2010 You cant query the result of a query, you can only manipulate the result through PHP - the way you do this entirely depends on how you want to manipulate the data. Have you got a specific task in mind? -cb- Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052312 Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 If you could post what it is you are trying to do it would help. You can perform conditional checking on query results, but you can't actualy query a result set once you have retrieved it out of the database. Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052315 Share on other sites More sharing options...
Tombie Posted May 3, 2010 Author Share Posted May 3, 2010 You cant query the result of a query, you can only manipulate the result through PHP - the way you do this entirely depends on how you want to manipulate the data. Have you got a specific task in mind? -cb- yeah, i have this query, which works fine on its own, however as a result of the database it returns multiple the same values $result=mysql_query("SELECT * FROM $stand WHERE id NOT IN (SELECT seatid FROM booking WHERE eventid = $event AND stand = '$stand')"); it then populates a dynamic drop down box with the available blocks, however due to the way the database is set out, that returns something like A1, A1, A1, A1, i had countered this before by using SELECT DISTINCT block FROM $stand but as far as im aware and ive tested, i cannot do something like that on the above query Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052317 Share on other sites More sharing options...
ChemicalBliss Posted May 3, 2010 Share Posted May 3, 2010 When your looping the results you could have a match array: $temporary = array(); // looping the results while($row = mysqlq_fetch_array($result)){ // Check if its been echoed before if(!isset($temporary[$row['block']])){ // Flag it as being echod, then echo it. $temporary[$row['block']] = 1; echo $row['block']; } } im no good at mysql but i bet there will be a single magical query for you . -cb- Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052336 Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 Hows about "SELECT * FROM $stand WHERE id NOT IN (SELECT seatid FROM booking WHERE eventid = $event AND stand = '$stand') GROUP BY id " (assuming id is the field that you are returning). Also, as a rule of thumb, avoid SELECT * wherever possible. Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052339 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2010 Share Posted May 3, 2010 Are the rows the exact same? Do you only need to select a certain column? Because to GROUP or use DISTINCT, the rest of the column data may not be what you want. Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052353 Share on other sites More sharing options...
Tombie Posted May 3, 2010 Author Share Posted May 3, 2010 Hows about "SELECT * FROM $stand WHERE id NOT IN (SELECT seatid FROM booking WHERE eventid = $event AND stand = '$stand') GROUP BY id " (assuming id is the field that you are returning). Also, as a rule of thumb, avoid SELECT * wherever possible. this post led me to the answer, thanks, instead of group by ID (which of course is different everytime and therefore does nothing i grouped it by the field which needed to be cut down to just 1 instance ie block) thanks for that. Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052359 Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 You're welcome. And I did say that the "id" field was an assumption Good luck Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052371 Share on other sites More sharing options...
Tombie Posted May 3, 2010 Author Share Posted May 3, 2010 You're welcome. And I did say that the "id" field was an assumption Good luck sorry for questioning your expertise did not read it specifically enough but yep thanks all the same Quote Link to comment https://forums.phpfreaks.com/topic/200544-mysqlphp-quickeasy-question/#findComment-1052373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.