Jump to content

mysql/php quick+easy question!


Tombie

Recommended Posts

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

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 :P.

 

-cb-

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.