asterixvader Posted December 8, 2006 Share Posted December 8, 2006 hello again.i'm back with another question:how to make a working "variable with many values" (if that's how they're called).this is my code:$query ="SELECT Name,Lastname from People where [b]Job=??[/b] ";i want to pick Name and Lastname from rows that have Job=5 and Job=7.i've tried:$Job1=5;$Job2=7;$Job3 = $Job1 = $Job2;and put $Job3 in "..where Job=$Job3";" but it didn't work, it picks rows with Job=5 only.i've also tried:$query ="SELECT Name,Lastname from People where Job=1 and Job=2 ";but it doesn't show anything this way.i've read something about arrays but i don't think it will work, will it?thanks! Link to comment https://forums.phpfreaks.com/topic/29878-working-multiple-values/ Share on other sites More sharing options...
drifter Posted December 8, 2006 Share Posted December 8, 2006 where ($job=1 OR $job=2 OR $job=3) Link to comment https://forums.phpfreaks.com/topic/29878-working-multiple-values/#findComment-137292 Share on other sites More sharing options...
kenrbnsn Posted December 8, 2006 Share Posted December 8, 2006 You almost had it with[code]<?php$query ="SELECT Name,Lastname from People where Job=1 and Job=2 ";?>[/code]But why, if you are looking for job=5 & job=7, did you put in 1 & 2?I assume you're looking for all rows where the "job" field is either 5 or 7, so try this:[code]<?php$query ="SELECT Name,Lastname from People where Job=5 OR Job=7 ";$rs = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());while($rw = mysql_fetch_assoc($rs)) echo $rw['Name'] . ' ' . $rw['Lastname'] . '<br>';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/29878-working-multiple-values/#findComment-137293 Share on other sites More sharing options...
artacus Posted December 8, 2006 Share Posted December 8, 2006 A little bit cleaner than having a daisy chain of OR's is to use INSELECT *FROM people WHERE job IN (3,5,7) Link to comment https://forums.phpfreaks.com/topic/29878-working-multiple-values/#findComment-137295 Share on other sites More sharing options...
asterixvader Posted December 8, 2006 Author Share Posted December 8, 2006 [quote author=kenrbnsn link=topic=117801.msg480916#msg480916 date=1165549721]You almost had it with[code]<?php$query ="SELECT Name,Lastname from People where Job=1 and Job=2 ";?>[/code]But why, if you are looking for job=5 & job=7, did you put in 1 & 2?I assume you're looking for all rows where the "job" field is either 5 or 7...[/quote]whoops, i meant 5 and 7!and the code you typed says "OR", but i want "AND". i don't know, i don't understand it so i don't know how it works.anyway, i tried artacus code and it worked fine!thanks you all again! Link to comment https://forums.phpfreaks.com/topic/29878-working-multiple-values/#findComment-137304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.