Re: [PHP] php - no results - display other message

2004-09-15 Thread John Nichel
Dustin Krysak wrote:
Hi there... I have a simple search page (mysql database), and I can get 
it to display the results no issues, but i was wondering how I could 
display a message stating there were no results, instead of just having 
the field blank. I am familiar with IF and ELSE statements, but I am not 
sure how to test the no result option from the results of a SQL query

thanks!
d
Depends on how you're recieving your results...
function doSearch ( $string ) {
$sql = SELECT *.blah, blah
more code;
if ( $result = 
return $result;
} else {
return false;
}
}
if ( $search = doSearch ( $terms ) ) {
// display results
} else {
// display no results found
}
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] php - no results - display other message

2004-09-15 Thread Chris Dowell
Or alternatively
$result = mysql_query(SELECT * FROM tablename);
if (mysql_num_rows($result))
{
 while ($row = mysql_fetch_row($result))
 {
   // display results
 }
}
else echo No results;
Hope this helps
Cheers
Chris
John Nichel wrote:
Dustin Krysak wrote:
Hi there... I have a simple search page (mysql database), and I can 
get it to display the results no issues, but i was wondering how I 
could display a message stating there were no results, instead of 
just having the field blank. I am familiar with IF and ELSE 
statements, but I am not sure how to test the no result option from 
the results of a SQL query

thanks!
d
Depends on how you're recieving your results...
function doSearch ( $string ) {
$sql = SELECT *.blah, blah
more code;
if ( $result = 
return $result;
} else {
return false;
}
}
if ( $search = doSearch ( $terms ) ) {
// display results
} else {
// display no results found
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] php - no results - display other message

2004-09-15 Thread John Holmes
From: Chris Dowell [EMAIL PROTECTED]
Or alternatively
$result = mysql_query(SELECT * FROM tablename);
if (mysql_num_rows($result))
{
 while ($row = mysql_fetch_row($result))
 {
   // display results
 }
}
else echo No results;
bah... you're wasting precious resources on a mysql_num_rows call... ;)
$result = mysql_query( ... );
if($row = mysql_fetch_assoc($result))
{
 do{
   //display results
 }while($row=mysql_fetch_assoc($result));
}
else
{ echo 'No results'; }
Millions ways to do it. :)
---John Holmes...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] php - no results - display other message

2004-09-14 Thread Dustin Krysak
Hi there... I have a simple search page (mysql database), and I can get 
it to display the results no issues, but i was wondering how I could 
display a message stating there were no results, instead of just having 
the field blank. I am familiar with IF and ELSE statements, but I am 
not sure how to test the no result option from the results of a SQL 
query

thanks!
d
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] php - no results - display other message

2004-09-14 Thread Gerard Samuel
Dustin Krysak wrote:
Hi there... I have a simple search page (mysql database), and I can get 
it to display the results no issues, but i was wondering how I could 
display a message stating there were no results, instead of just having 
the field blank. I am familiar with IF and ELSE statements, but I am not 
sure how to test the no result option from the results of a SQL query

Count the results from the search, maybe with
http://us2.php.net/manual/en/function.mysql-num-rows.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] php - no results - display other message

2004-09-14 Thread Dennis Seavers
mysql_num_rows () will tell you how many rows return in the query

 [Original Message]
 From: Dustin Krysak [EMAIL PROTECTED]
 To: PHP [EMAIL PROTECTED]
 Date: 09/14/2004 9:37:24 PM
 Subject: [PHP] php - no results - display other message

 Hi there... I have a simple search page (mysql database), and I can get 
 it to display the results no issues, but i was wondering how I could 
 display a message stating there were no results, instead of just having 
 the field blank. I am familiar with IF and ELSE statements, but I am 
 not sure how to test the no result option from the results of a SQL 
 query

 thanks!

 d

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php