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.
18 Replies - 2127 Views - Last Post: 05 March 2005 - 04:01 PM
Replies To: Checking If A Row Has Been Returned
#2
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
if (mysql_num_rows($res)==1) {
Thanks
#3
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?
#4
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 ";
#5
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
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
#6
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.
#7
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?
Does this mean there is no way of finding out if a record has been returned?
#8
Re: Checking If A Row Has Been Returned
Posted 05 March 2005 - 08:35 AM
isset($query['field_id'])?
#9
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:
Using ADODB style objects and collections, the correct way to check to see if there are any records would be
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()
}
#10
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.
Thanks again.
#11
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.
#12
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.
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.
#13
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:
$rs is the recordset retuned from your query...it will contain either some records or no records...it is based on your query.
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.
#14
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.
#15
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.
|
|

New Topic/Question
Reply



MultiQuote




|