search result error message
am 21.12.2006 21:00:29 von Chris CarterHi,
The below mentioned code works fine. Connects to the database, fetches the
result, and displays neatly in a table. If there is no data then it jumps to
the if condition and displays the error message. BUT if the 'if' condition
is running and no data is present the Table headings and the bottm of empty
table is still displayed above the error message. Can you please check and
share with me as in where exactly the logic is wrong.
---------- -------------- Code --------------- ------------
Your favorites search result
Your favorites
Shop name |
---|
$shopname |
if ($num == 0){
echo "
result, index.htm please try again .
}?>
--
View this message in context: http://www.nabble.com/search-result-error-message-tf2867391. html#a8014018
Sent from the Php - Database mailing list archive at Nabble.com.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: search result error message
am 21.12.2006 21:17:20 von Trevor GryffynSorry, don't have time to test and noodle through why yours may or may not be working, but I see some differences in how you're doing it and how we tend to do it here.
After doing the connection and database selection, this is how we handle stuff (simplified):
$query = "select * from sometable";
$result = mysql_query($query);
$count = mysql_affected_rows();
while ($row = mysql_fetch_assoc($result)) {
// do some stuff
$address = $row['address']; // example of how to get/use data returned
}
Nothing inside the while construct should execute if you get zero results.
You really don't need to use the mysql_affected_rows() either unless you want to test for zero results and display an error message, like I believe you wanted to do.
-TG
= = = Original message = = =
Hi,
The below mentioned code works fine. Connects to the database, fetches the
result, and displays neatly in a table. If there is no data then it jumps to
the if condition and displays the error message. BUT if the 'if' condition
is running and no data is present the Table headings and the bottm of empty
table is still displayed above the error message. Can you please check and
share with me as in where exactly the logic is wrong.
---------- -------------- Code --------------- ------------
Your favorites search result
Your favorites
~~~
~~~~~
~~~~~
Shop name |
---|
$shopname |
if ($num == 0)
echo "
result, index.htm please try again .
~
?>
~~~~~
--
View this message in context: http://www.nabble.com/search-result-error-message-tf2867391. html#a8014018
Sent from the Php - Database mailing list archive at Nabble.com.
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: search result error message
am 21.12.2006 21:36:08 von Niel ArcherHi,
there's no 'logic' error at all that I can see. It's more a design
error as it doesn't do the job the way that you describe it at all.
What actually happens is that the starting HTML (heading and table
start) is output before the database is even contacted, so there's no
way for you to take the table back if you don't receive any relevant
hits.
try something more like this:
// database information
$host = 'xxx';
$user = 'xxx';
$password = 'xxx';
$dbName = 'xxx';
mysql_connect(localhost,$user,$password);
@mysql_select_db($dbName ) or die( "Sorry But There Seems To Be A Problem
Connecting To The Database");
$query="SELECT * FROM shop";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
if ($num) {
?>
Your favorites search result
Your favorites
Shop name |
---|
$shopname |
} else {
echo "
result, index.htm please try again .
}
You'll probably need to polish this some, because I quickly cut/pasted
it before I go down the pub.
Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php