473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Testing if a DB query finds something or not.

LRW
I'm trying to make an If/Else option in the case a database query comes back
with nothing. But when I use the code included below, it always comes back
saying there is no result.
I'm guessing it's because it's asking if there are any results to the query
after it's already finished and the array created.
How can I get it to say basically: If there are no database records fitting
the query, then do this...otherwise do this?
Thanks!!
Liam

$query_RS_con = "SELECT * FROM $conTBL WHERE $field = \"$item\"";
$RS_con = @mysql_query($query_RS_con, $connection) or die("Couldn't query:
" . mysql_error());
while ($row_RS_con = mysql_fetch_array($RS_con)) {
$procid = $row_RS_con['uid'];
$procid2 = $row_RS_con['id'];
$procpass = $row_RS_con['cont_password'];
}
if (!($row_RS_con)) {
$statusmsg = "Your Username was not found. Please go back and try
again.<br><br><A HREF='javascript:history.go(-1)'>Click Here to go back and
try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
} else {
if (($pass1) == ($procpass)) {
header("Location:
http://www.url.org/contact/change.php?uid=$procid$procid2");
} else {
$statusmsg = "Your Password did not match your Username. Please go back
and try again.<br><br><A HREF='javascript:history.go(-1)'>Click Here to go
back and try again.</a><br>(You may need to click the ACCESS menu option
twice.)<br>";
}
}
Jul 17 '05 #1
1 1744
"LRW" <dr***@NOSPAHMcelticbear.com> writes:
I'm trying to make an If/Else option in the case a database query comes back
with nothing. But when I use the code included below, it always comes back
saying there is no result.
I'm guessing it's because it's asking if there are any results to the query
after it's already finished and the array created.
Almost right -- see below.
How can I get it to say basically: If there are no database records fitting
the query, then do this...otherwise do this?

$query_RS_con = "SELECT * FROM $conTBL WHERE $field = \"$item\"";
$RS_con = @mysql_query($query_RS_con, $connection) or die("Couldn't query:
" . mysql_error());
while ($row_RS_con = mysql_fetch_array($RS_con)) {
$procid = $row_RS_con['uid'];
$procid2 = $row_RS_con['id'];
$procpass = $row_RS_con['cont_password'];
}
The above while loop is executed until $row_RS_con becomes false.
Then you do this:
if (!($row_RS_con)) {


$row_RS_con should always be false here -- otherwise you'd still
be in the while loop.

You can use mysql_num_rows() to find out how many rows a SELECT
query returned.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #2

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

Similar topics

5
by: Rahul | last post by:
HI. Python , with its support of arbit precision integers, can be great for number theory. So i tried writing a program for testing whether a number is prime or not. But then found my function...
354
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets...
3
by: splashout1 | last post by:
I am trying to set up a search facility by giving the user a form for them to enter a variety of criteria. They will either know the exact criteria they are looking for or will not. Therefore i...
8
by: Michael van der Veeke | last post by:
Hi All, Does anyone use any regression testing tools with MS Access? We have tried a few and none seem to work very well with a MS Access Front end and I need one. Can anyone provide any...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
24
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
6
by: Jim Mandala | last post by:
Using MS Access 2003 with SQL Server 2005 as a backend: I am trying to automatically check for collisions in a table of appointments with an appointment currenlty being saved from the form...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.