Jump to content

working multiple values


asterixvader

Recommended Posts

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

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
[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!

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.