PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Sat Mar 18, 2006 12:44 am
Code: Select all
if (isset($cat)){
if ($r = mysql_query($query1) or die(mysql_error()))
{
//print
while ($row = mysql_fetch_array ($r))
{
print "<a href=\"list.php?id={$row['id']}\"><IMG SRC=\"{$row['smpic']}\" ALT=\"{$row['name']}\"></a>";
print "{$row['name']}";
}
}else {
print " No Rides Here! <br> If you would like to have your ride added to this section email us";
}
}
The No Rides Here blah blah only prints if theres no var in the url even though i put it under the mysql if statement...
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Sat Mar 18, 2006 1:04 am
tried changing something an now i got a parse error on line 27 which is "}else{"
Code: Select all
while ($row = mysql_fetch_array ($r))
{
print "<a href=\"list.php?id={$row['id']}\"><IMG SRC=\"{$row['smpic']}\" ALT=\"{$row['name']}\"></a>";
print "{$row['name']}";
}else {
print " No Rides Here! <br> If you would like to have your ride added to this section email us";
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 18, 2006 1:07 am
in your new code, the else is being associated with the while() which is not legal.
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Sat Mar 18, 2006 1:09 am
oh.
it should go with thte second if then right ?
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Sat Mar 18, 2006 1:23 am
what does $r return if nothing isretrieved?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 18, 2006 1:28 am
If the result set is empty, it's a resource. If the query failed, it'll be false and the die() will be run.
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Sat Mar 18, 2006 1:29 am
empty as in " " or 0 or null ?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 18, 2006 1:31 am
empty as in no records that matched the criteria were found.
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Sat Mar 18, 2006 1:34 am
i understand that, just what get returned to the variable? nothing at all so it set to $r="" ?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 18, 2006 1:45 am
I told you, a resource.
Noobie
Forum Commoner
Posts: 85 Joined: Sun May 15, 2005 11:38 am
Post
by Noobie » Sat Mar 18, 2006 11:07 am
I have a similar issue - mainly because I would like a message echoed if the result set is empty. Is there a way of doing that?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 18, 2006 11:17 am
Have a look through the functions MySQL support exposes. I'll give you a hint, it has something to do with rows.
http://php.net/ref.mysql
Noobie
Forum Commoner
Posts: 85 Joined: Sun May 15, 2005 11:38 am
Post
by Noobie » Sat Mar 18, 2006 12:21 pm
Not fair (stamps feet) you always make me find it myself! What's wrong with a little spoon-feeding once in a while eh?
I don't know if it's "right" but it works - I included this:
Code: Select all
if (mysql_num_rows($result) == 0) {
echo "<p>" . "Nothing to see here, move along now" . "</p>";
exit;
}
Thanks for pointing me in the right direction.
anticore
Forum Newbie
Posts: 21 Joined: Sat Mar 11, 2006 11:37 pm
Post
by anticore » Sat Mar 18, 2006 12:31 pm
Code: Select all
if empty($r)
{
print " The Message";
}
would that work too ?
asgerhallas
Forum Commoner
Posts: 80 Joined: Tue Mar 14, 2006 11:11 am
Location: Århus, Denmark
Post
by asgerhallas » Sat Mar 18, 2006 1:00 pm
no... wouldn't work - if $r is a ressource it's not empty.
noobies version is the correct one...