473,503 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php querying

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
7 1209
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
>
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2242
by: Michael Whittaker | last post by:
Hello! I have a problem with my php script. The script's task is to search an IP-Database with ranges as entries and find, in which range the entered IP is. OK, I've queried the MySQL-Results...
1
1678
by: Ravi Shankar | last post by:
Hi all, I have a calendar application( like Microsoft Outlook) writtn in Java.Whenever an event is created, we can set SMS/EMAIL notification. Hence when an event is created, I am storing that...
3
1817
by: Keith | last post by:
I am fairly new to SQL so sorry if this is a really dumb question. I have a small (still) SQL database, which I am trying to query from an ASP page. The field I am querying is of DATETIME data...
1
2084
by: valexena | last post by:
After a few minutes of querying the database my session disconnects abruptly. Can somebody help me and tell why can be happening? -- Posted via http://dbforums.com
1
1402
by: Ron L. | last post by:
Hi, Any suggestions for a good intorudction to OLAP querying with MDX? Thanks, Ron. -- Performance Intelligence, Inc. Spy 4 DB2 - http://www.pireporting.com/spy4db2.html
6
2633
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
5
2348
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
3
1570
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but...
2
1731
by: RajSharma | last post by:
Hi, I am facing a problem regarding querying thru a large table having millions of rows....... Its hanging in between while querying for all those rows Can anybody suggest me a query regarding :...
4
1514
by: =?Utf-8?B?U3VoYXMgVmVuZ2lsYXQ=?= | last post by:
Hello, I am facing an issue while querying Active directory using C# code with system.DirectoryServices namespace. Here is the path for my LDAP - "LDAP://CN=XY - C++/Unix and other,...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.