Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,461 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,368 people online right now. Registration is fast and FREE... Join Now!




Checking If A Row Has Been Returned

2 Pages V  1 2 >  
Reply to this topicStart new topic

Checking If A Row Has Been Returned

bexlhoward1
post 5 Mar, 2005 - 04:55 AM
Post #1


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

Hi, I need to find out if a row has been returned, does anyone know how I would do this, I am using Access.

Thanks

Bex.
User is offlineProfile CardPM

Go to the top of the page

bexlhoward1
post 5 Mar, 2005 - 06:05 AM
Post #2


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

This is the line that i need to work with Access rather than mySQL:

if (mysql_num_rows($res)==1) {

Thanks
User is offlineProfile CardPM

Go to the top of the page

bexlhoward1
post 5 Mar, 2005 - 06:09 AM
Post #3


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

I dont think I can use mySQL for an Access database can I?
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 5 Mar, 2005 - 06:13 AM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


I believe it is odbc_num_rows(). Alternatively, you can run a loop of the the returned recordsets and count them, or even have a separate query to get the count, something like
CODE

$count="SELECT count(*) as result FROM (".$myquery.") AS numofrecords ";
User is online!Profile CardPM

Go to the top of the page

bexlhoward1
post 5 Mar, 2005 - 06:24 AM
Post #5


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

I am trying to find out if there are no rows returned. The first option gives me an error, I am using connecting do the database using this code:
if (!$conn = new COM("ADODB.Connection"))
exit("Unable to create an ADODB connection"); could this be why?

Im not really sure how your second suggestion would work.

Thanks
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 5 Mar, 2005 - 06:32 AM
Post #6


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


You have to use the odbc_connect() function if you want to use any other odbc functions...it's preferred over the COM objects.
User is online!Profile CardPM

Go to the top of the page

bexlhoward1
post 5 Mar, 2005 - 06:46 AM
Post #7


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

Im affraid I cant because of restrictions on the server. I have been told I have to use COM.

Does this mean there is no way of finding out if a record has been returned?
User is offlineProfile CardPM

Go to the top of the page

snoj
post 5 Mar, 2005 - 07:35 AM
Post #8


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


isset($query['field_id'])?
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 5 Mar, 2005 - 08:10 AM
Post #9


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


It's really better to use inherent sql and related php object members when you can...check out this example of a DSNless connection with php - for full code, goto JuicyStudio, that's where this example is from:
CODE

if (!$conn = new COM("ADODB.Connection"))
       exit("Unable to create an ADODB connection<br>");
   $strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("\db\search.mdb");
   $conn->open($strConn);
   $strSQL = "SELECT * FROM mytable";
   $rs = $conn->execute($strSQL);

Using ADODB style objects and collections, the correct way to check to see if there are any records would be

CODE

if($rs->EOF)
{
//there are no records
}
else
{
//there are some records
//number of records can usually be accessed through the $rs->recordset()
}
User is online!Profile CardPM

Go to the top of the page

bexlhoward1
post 5 Mar, 2005 - 08:52 AM
Post #10


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

Hi, yes this is the way I have set it up. This statement does not work because there are records in the database just no records matching the query. This means I get a horrible error. Any ideas?

Thanks again.
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 5 Mar, 2005 - 08:59 AM
Post #11


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


The EOF should be catching the fact that no records have been returned...that's it's function. What is the error you're getting? Post it exactly please.
User is online!Profile CardPM

Go to the top of the page

bexlhoward1
post 5 Mar, 2005 - 09:05 AM
Post #12


New D.I.C Head

*
Joined: 4 Feb, 2005
Posts: 40

The error (which is staring to get really annoying now) is:

Warning: main(): PropGet() failed: Exception occurred. Source: ADODB.Field Description: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. in e:\webareas\hr112\easyfly\pages\results.php on line 263

Line 263 is where the first variable containing data from the database is printed.

Thanks.
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 12:32PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month