• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

"OR" in queries?

Lucky13

New Member
Hello...I want something like this:

When I go to index.php?id=x or index.php?name=x, if gets the same info for the record, but if I just go to index.php, it does something else. This is what I have:

if ($id OR $name) {
if ($id) {
blah blah FROM database WHILE id=$id
} elseif {
blah blah FROM database WHILE name=$name
}
(this is the individual record)
echo " . $rows[name] . ";
} else {
(this is a list of all of the records)
blah blah
}

Anyone have any ideas? Thank you very much.

~Lucky13
 
wouldn't you just put the HTML page you want displayed with just index.php between the braces of the last else { } statement?
 
That's what I would have through, but it said that the procedure of calling the last query (under "if ($name) {") wasn't supported on my server...
 
|| is just another way of saying OR
why are you using an elseif statement without giving it anything
either you give it another condition

elseif($name) {
yadayada
}

or you can just make it else

else {
yadayada
}

Also, note if you take the first option you can make it bullet proof by adding another else statement below it. I don't see how anything could get through after your OR statement, but if you're feeling like extra safety take option one. If you're feeling like shorter scripts take option two...
 
OK...it's not working. This is what I have:
PHP:
if ($id || $name) {
 if ($id) {
   $result = mysql_query("SELECT * FROM kod WHERE id=$id",$db);
   $myrow = mysql_fetch_array($result);
 } elseif ($name) {
   $result = mysql_query("SELECT * FROM kod WHERE name=$name",$db);
   $myrow = mysql_fetch_array($result);
 } else { 
   echo "Unable to comply";
 }
yada
} else {
yade

It works fine if I go to Roster.php?id='x', but when I go to Roster.php?name='y' it says that it has a problem with the line that says
PHP:
$result = mysql_query("SELECT * FROM kod WHERE name=$name",$db);

I'm stuck. Can anyone help?

Thanks
Lucky
 
No...the column "name" is there, and it's full. It says

Warning: Supplied argument is not a valid MySQL result resource in /home/niaad/niaad-www/kod/roster.php on line 34

Line 34 is when it call the query with the name=$name stuff.
 
2 things

"SELECT * FROM kod WHERE name='$name'",

as it's a text string



put

if ($result=mysql_query(.....)){ do stuff }
else {your error msg}

as returns false if a db error occurs so you can catch errors
 
HORRAY!

Lucifer is smart! You were right about the whole thing with the text string. I'll have to remember that :)

Thanks a lot!
~Lucky13
 
Back
Top