473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with select count(*)

Ben
Hi,

I have a problem with this query:
$link = mysql_connect("localhost", "root", "pw");
$dbsel = mysql_select_db('mydb', $link);
$lol='bibi';

$sql = "select count(*) as totuur from studres where where dag>= curdate()
AND logon='" . $lol . "'";
$result = mysql_query($sql);
$row = mysql_fetch_field($result,0);
// J'ai essayé avec: $row = mysql_fetch_row($result);
$totu=$row[0];
The error is on line: $row = mysql_fetch_field($result,0):
Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result
resource in c:\Inetpub\wwwroot\myfile.php on line 74
Thanks
Ben
Dec 19 '05 #1
2 5205
"Ben" <sdvs@qcsq> wrote in message
news:M8********************@scarlet.biz...
Hi,

I have a problem with this query:
$link = mysql_connect("localhost", "root", "pw");
$dbsel = mysql_select_db('mydb', $link);
$lol='bibi';

$sql = "select count(*) as totuur from studres where where dag>= curdate()
AND logon='" . $lol . "'";

You have WHERE twice in "...from studres where where dag...", try what
happens if you remove the extra where. This is one of the reasons why sql
keywords should be written in CAPITAL letters. It's easier to spot the error
if you write:
"SELECT COUNT(*) AS totuur FROM studres WHERE WHERE dag>= CURDATE() AND
logon='$lol'"

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
an*******************@gmail.com.NOSPAM.invalid
Dec 19 '05 #2
Kimmo Laine wrote:
"Ben" <sdvs@qcsq> wrote in message
news:M8********************@scarlet.biz...
Hi,

I have a problem with this query:
$link = mysql_connect("localhost", "root", "pw");
$dbsel = mysql_select_db('mydb', $link);
$lol='bibi';

$sql = "select count(*) as totuur from studres where where dag>= curdate()
AND logon='" . $lol . "'";


You have WHERE twice in "...from studres where where dag...", try what
happens if you remove the extra where. This is one of the reasons why sql
keywords should be written in CAPITAL letters. It's easier to spot the error
if you write:
"SELECT COUNT(*) AS totuur FROM studres WHERE WHERE dag>= CURDATE() AND
logon='$lol'"


And if you would have checked the result of the mysql_query() call, you
would have found your problem.

$result = mysql_query($sql);
if ($result) {
$row = mysql_fetch_field($result,0);
// J'ai essayé avec: $row = mysql_fetch_row($result);
$totu=$row[0];
}
else
echo "MySQL error: " . mysql_error();
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Dec 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: MyaTiX | last post by:
Hi Can someone please help! I am having a problem with a form! I need to be able to pull information from one table when the page loads and update another table after I have made changes but the...
3
by: Nicolas Payre | last post by:
Hi, I have the following SQL that I want to use to update a table. It doesn't work ! Does someone knows why? ** I Know it could be done easy with a CURSOR FOR LOOP, but still... Thanks for...
6
by: Bill | last post by:
I've created this: SELECT c.ProjectID, Count(c.ID) as 'Registrants', Count(dt.Hits) as 'Submissions' FROM CME_TBL c JOIN (SELECT ProjectID, Count(*) as Hits FROM CME_TBL
3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
3
by: Robert | last post by:
Greetings I have been trying to write a script that will list out the size of each user table in a specified DB. I am running into a scoping problem when trying to format my display. I am sure...
1
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
4
by: infiniti | last post by:
Hi, I am coming across problems in trying to EFFICIENTLY merge to XML files into one which involves transposing the rows into columns so that I can either generate a single flat xml file or store...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.