By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

php querying

P: n/a
where is the error in a query performed with php in this script?

<?php
@ $db=mysql_pconnect('localhost', 'database_name', 'password');
if (!$db)
{
echo 'conneciton eror';
exit;
}
else
{
echo 'connection on!';
}
mysql_select_db('books'); //books: table created previously.
$query="select * from orders"; //orders: a table that i have
previosly created.
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if ($num_results = 0)
{
echo'<br><br>nothing to dispaly';
}
else
{
echo'<br><br>here are the results: $num_results';
}
?>

Jun 4 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Jun 4, 12:36 pm, vinnie <centro.ga...@gmail.comwrote:
where is the error in a query performed with php in this script?

<?php
@ $db=mysql_pconnect('localhost', 'database_name', 'password');
if (!$db)
{
echo 'conneciton eror';
exit;
}
else
{
echo 'connection on!';
}
mysql_select_db('books'); //books: table created previously.
$query="select * from orders"; //orders: a table that i have
previosly created.
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
if ($num_results = 0)
{
echo'<br><br>nothing to dispaly';}

else
{
echo'<br><br>here are the results: $num_results';}

?>
wrong: if ($num_results = 0)

right: if ($num_results == 0)

Jun 4 '07 #2

P: n/a
>
wrong: if ($num_results = 0)

right: if ($num_results == 0)
ok, but why i don't get any results from the query?

Jun 4 '07 #3

P: n/a
Message-ID: <11**********************@k79g2000hse.googlegroups .comfrom
vinnie contained the following:
>where is the error?
Here
>if ($num_results = 0)
= is the assignment operator. You will never display any results since
this will always evaluate to true.

Try
if ($num_results <1)
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 4 '07 #4

P: n/a
Message-ID: <11*********************@m36g2000hse.googlegroups. comfrom
vinnie contained the following:
>
>>
wrong: if ($num_results = 0)

right: if ($num_results == 0)

ok, but why i don't get any results from the query?
Change this
echo'<br><br>here are the results: $num_results';
to this
echo '<br><br>here are the results: '.$num_results;

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 4 '07 #5

P: n/a
Change this
echo'<br><br>here are the results: $num_results';
to this
echo '<br><br>here are the results: '.$num_results;
thanks Geoff, it works perfectly now. But what's the difference? Is
not the same thing?

Jun 4 '07 #6

P: n/a
vinnie wrote:
>Change this
echo'<br><br>here are the results: $num_results';
to this
echo '<br><br>here are the results: '.$num_results;

thanks Geoff, it works perfectly now. But what's the difference? Is
not the same thing?
The difference is that unlike double-quoted strings, single-quoted
strings do not replace variable names inside the quotes with variable
values. The version that works concatenates your string with the value
of $num_results variable.

You could also have written

echo "<br><br>here are the results: $num_results";
Jun 4 '07 #7

P: n/a
Message-ID: <46********@news.bihnet.bafrom Denis Gerina contained the
following:
>thanks Geoff, it works perfectly now. But what's the difference? Is
not the same thing?

The difference is that unlike double-quoted strings, single-quoted
strings do not replace variable names inside the quotes with variable
values. The version that works concatenates your string with the value
of $num_results variable.
What he said.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 4 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.