473,800 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...otherwis e do this?
Thanks!!
Liam

$query_RS_con = "SELECT * FROM $conTBL WHERE $field = \"$item\"";
$RS_con = @mysql_query($q uery_RS_con, $connection) or die("Couldn't query:
" . mysql_error());
while ($row_RS_con = mysql_fetch_arr ay($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='javascrip t: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("Locatio n:
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='javascrip t: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 1771
"LRW" <dr***@NOSPAHMc elticbear.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...otherwis e do this?

$query_RS_con = "SELECT * FROM $conTBL WHERE $field = \"$item\"";
$RS_con = @mysql_query($q uery_RS_con, $connection) or die("Couldn't query:
" . mysql_error());
while ($row_RS_con = mysql_fetch_arr ay($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
2727
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 painfully slow.Here is the function : from math import sqrt def isPrime(x): if x%2==0 or x%3==0: return 0
354
15932
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 hooked up to interfaces. The Gtk is more than enough gui.
3
289
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 set a query up using the forms controls as criteria as such !! or !!is null for each of the search criteria which allows me to search for one or more criteria at once and works lovely.
8
4924
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 suggestions? Thanks Michael
14
2758
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
3540
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 performs MySQL queries to a database. These queries are performed at regular intervals. Basically it is looking for fields that match certain criterias. Such fields are not present at all time. When the program finds such field, it then takes
1
3167
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 combined. **Max Date/Time Query-Finds the most recent updated record based on the time and date (Correct Results Returned) SELECT .panelNumber, Max(.locDate) AS MaxOflocDate, Max(.completionTime) AS MaxOfcompletionTime, .jobNumber, .panelID FROM , ...
24
2531
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 you ensure that the code will work correctly in the future? Short version:
6
2825
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 "FormAppt". I do this by calculating an end time form the start time and duration. Then I have two queries. The first one, "QueryA", finds all the appointments that day for that staff person which start before the end time of the appointment currently...
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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 we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.