Checking If A Row Has Been Returned

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 2270 Views - Last Post: 05 March 2005 - 04:01 PM Rate Topic: -----

#1 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Checking If A Row Has Been Returned

Posted 05 March 2005 - 05:55 AM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: Checking If A Row Has Been Returned

#2 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 07:05 AM

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

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

Thanks
Was This Post Helpful? 0
  • +
  • -

#3 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 07:09 AM

I dont think I can use mySQL for an Access database can I?
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 07:13 AM

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
$count="SELECT count(*) as result FROM (".$myquery.") AS numofrecords ";


Was This Post Helpful? 0
  • +
  • -

#5 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 07:24 AM

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
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 07:32 AM

You have to use the odbc_connect() function if you want to use any other odbc functions...it's preferred over the COM objects.
Was This Post Helpful? 0
  • +
  • -

#7 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 07:46 AM

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?
Was This Post Helpful? 0
  • +
  • -

#8 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 08:35 AM

isset($query['field_id'])?
Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 09:10 AM

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:
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

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


Was This Post Helpful? 0
  • +
  • -

#10 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 09:52 AM

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.
Was This Post Helpful? 0
  • +
  • -

#11 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 09:59 AM

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.
Was This Post Helpful? 0
  • +
  • -

#12 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 10:05 AM

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.
Was This Post Helpful? 0
  • +
  • -

#13 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 10:12 AM

You have to check and see if there are any records before you access a field from that record...as posted above, your code should follow the format below:
if($rs->EOF)
{
\\there is no data...do NOT try and access members...
}
else
{
//there is data...this is the section in which you would access members
}


$rs is the recordset retuned from your query...it will contain either some records or no records...it is based on your query.
Was This Post Helpful? 0
  • +
  • -

#14 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 10:27 AM

I seem to have this working now! Thank you so much for the help. Wish I could use MySQL, would be so much easier! Thanks.
Was This Post Helpful? 0
  • +
  • -

#15 cyberscribe  Icon User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: Checking If A Row Has Been Returned

Posted 05 March 2005 - 01:38 PM

bexlhoward1, on Mar 5 2005, 10:27 AM, said:

Wish I could use MySQL, would be so much easier!

Yep.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2