Jump to content

searching a array while selecting from mysql


Shadowing

Recommended Posts

Hey guys, im trying to select only certain rows that matchs the address in a array. Not sure how to do this

 

This is making the array

$siege_check3 = "SELECT address FROM planets WHERE siege='".mysql_real_escape_string($_SESSION['goauld'])."'"; 
$siege_check2 = mysql_query($siege_check3) or die(mysql_error());
$arr = array();	
while($siege_check1 = mysql_fetch_array($siege_check2)) {

$siege_planets = $siege_check1['address'];

$arr[] = $siege_planets;
} 

Then I want to AND grab rows where defender_planet equals one of the address in the array above

tried using in_array but telling me its not a valid function

 

             $alert3 = "SELECT * FROM travel WHERE defender_id = '" .($_SESSION['user_id'])."' 
             AND stance = 2 AND stealth_tech < '".($stealth_tech)."' 
             AND address=  in_array(defender_planet,$arr) ORDER BY arrived_time DESC"; 

             $alert2 = mysql_query($alert3) or die(mysql_error());

while($alert1 = mysql_fetch_assoc($alert2)) {

}

Link to comment
Share on other sites

 

opps had a typo. and i posted way more code then needed. its suppose to be

 

$arr[] = $siege_planets;

AND defender_planet=  in_array(defender_planet,$arr) ORDER BY arrived_time DESC"; 

 

 

so trying to check if defender_planet matches any in the array

Link to comment
Share on other sites

thanks guys never would of thought to look at IN. I've never had to used it before.

 

Im having a syntax issue though

im sure its cause the manual is saying it should look like ('1','2','3') and the values are numbers so i guess i need a quote on each side of each value?

Maniac did you mean I need to implode it into a variable or do it with in the string of the query

 

I assumed you meant like this

 

 

$arr[] = $siege_planets;
$implode = implode(", ",$arr);

$alert3 = "SELECT * FROM travel WHERE defender_planet = IN $implode AND stance = 2 
AND stealth_tech < '".($stealth_tech)."' ORDER BY arrived_time DESC"; 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.