473,320 Members | 2,110 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,320 software developers and data experts.

Finding the results of a query

I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
..mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);

I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:

if (some expression){
perform this code
}
else{
do this
}

Nov 21 '06 #1
8 1377

Jerim79 wrote:
I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);

I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:

if (some expression){
perform this code
}
else{
do this
}
I guess I could load the results into an array using fetchrow(), and
then check to see if it is NULL or contains data. If it is NULL, then
it didn't find it and I can do one set of instructions. If it is not
NULL, I can do another set of instructions. I am not sure that is the
best way to do it though. I would think that $result would change on
based on finding it or not, and I could just easily check against
$result.

Nov 21 '06 #2

"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);

I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:

if (some expression){
perform this code
}
else{
do this
}
$numRows = mysql_num_rows($result);

then test on whether $numRows is greater than zero.

Shelly
Nov 21 '06 #3

Shelly wrote:
"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);

I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:

if (some expression){
perform this code
}
else{
do this
}

$numRows = mysql_num_rows($result);

then test on whether $numRows is greater than zero.

Shelly
Thanks, that worked perfectly. Now I need to take the first name and
the last name out of the query result and convert them to lower case. I
understand there is a PHP function for lower case. My question is how
to access specific columns in the result.

Nov 21 '06 #4

Jerim79 wrote:
Shelly wrote:
"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:
>
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);
>
I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:
>
if (some expression){
perform this code
}
else{
do this
}
>
$numRows = mysql_num_rows($result);

then test on whether $numRows is greater than zero.

Shelly

Thanks, that worked perfectly. Now I need to take the first name and
the last name out of the query result and convert them to lower case. I
understand there is a PHP function for lower case. My question is how
to access specific columns in the result.

SELECT lower(FNAME) lc_fname, lower(LNAME) lc_lname
FROM (table)
WHERE FNAME=('$FName')
AND
NAME=('$LName')

Nov 21 '06 #5

strawberry wrote:
Jerim79 wrote:
Shelly wrote:
"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);

I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:

if (some expression){
perform this code
}
else{
do this
}

>
$numRows = mysql_num_rows($result);
>
then test on whether $numRows is greater than zero.
>
Shelly
Thanks, that worked perfectly. Now I need to take the first name and
the last name out of the query result and convert them to lower case. I
understand there is a PHP function for lower case. My question is how
to access specific columns in the result.


SELECT lower(FNAME) lc_fname, lower(LNAME) lc_lname
FROM (table)
WHERE FNAME=('$FName')
AND
NAME=('$LName')
I tried that and it didn't seem to work. I am converting my FName and
LName as they are posted from the form page.
$FName=strtolower($_POST["$FName"])

That seemed to work, as valid data was returning negative results
before making the changes you suggested. So now I just need to get the
SQL results into lower case. I am curious as to lc_fname and lc_lname.
Are those new variable names that I should check against or do they
replace FNAME automatically?

Nov 21 '06 #6

Jerim79 wrote:
strawberry wrote:
Jerim79 wrote:
Shelly wrote:
"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:
>
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);
>
I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:
>
if (some expression){
perform this code
}
else{
do this
}
>

$numRows = mysql_num_rows($result);

then test on whether $numRows is greater than zero.

Shelly
>
Thanks, that worked perfectly. Now I need to take the first name and
the last name out of the query result and convert them to lower case. I
understand there is a PHP function for lower case. My question is how
to access specific columns in the result.

SELECT lower(FNAME) lc_fname, lower(LNAME) lc_lname
FROM (table)
WHERE FNAME=('$FName')
AND
NAME=('$LName')

I tried that and it didn't seem to work. I am converting my FName and
LName as they are posted from the form page.
$FName=strtolower($_POST["$FName"])

That seemed to work, as valid data was returning negative results
before making the changes you suggested. So now I just need to get the
SQL results into lower case. I am curious as to lc_fname and lc_lname.
Are those new variable names that I should check against or do they
replace FNAME automatically?
They're just aliases.

SELECT FNAME, lower(FNAME) AS lc_fname, LNAME, lower(LNAME) AS lc_lname
FROM (table)
WHERE FNAME=('$FName')
AND
NAME=('$LName')

is 'NAME' right on the last line?

This should work. Although php is case sensitive, mysql isn't - unless
you include BINARY in the query- so I can't quite see why you need to
do all that stuff.

Nov 21 '06 #7

"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
>
Shelly wrote:
>"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
>I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);

I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:

if (some expression){
perform this code
}
else{
do this
}

$numRows = mysql_num_rows($result);

then test on whether $numRows is greater than zero.

Shelly

Thanks, that worked perfectly. Now I need to take the first name and
the last name out of the query result and convert them to lower case. I
understand there is a PHP function for lower case. My question is how
to access specific columns in the result.
$row = mysql_fetch_assoc($result);
$lastName = strtolower($row['LNAME']);
$firstName = strtolower($row'FNAME']);

Shelly
Nov 21 '06 #8

Shelly wrote:
"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...

Shelly wrote:
"Jerim79" <my***@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I am working on a script that will query a database for a FNAME/LNAME
combo. If it finds the combo, I need it to do one set of instructions.
If it doesn't find it, I need it to do something else. What I can't
figure out is what variable to check against. Here is what I have for
the relevant part of the script:

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($databasename) or die ("Cannot connect to database"
.mysql_error());
$query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND
NAME=('$LName')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close($connection);

I tried checking the value of $result to see if it changed depending on
whether or not it found the selection. It does not. I just can't figure
out what to use for:

if (some expression){
perform this code
}
else{
do this
}


$numRows = mysql_num_rows($result);

then test on whether $numRows is greater than zero.

Shelly
Thanks, that worked perfectly. Now I need to take the first name and
the last name out of the query result and convert them to lower case. I
understand there is a PHP function for lower case. My question is how
to access specific columns in the result.

$row = mysql_fetch_assoc($result);
$lastName = strtolower($row['LNAME']);
$firstName = strtolower($row'FNAME']);

Shelly
Thak you for the help. I didn't have to format the MySQL data after
all. The data stored in the database had capital letters. However, my
correct data returns true no matter how I capitalize it. The wrong data
returns false. So it just seems to work. I didn't have to make any
change to the MySQL query at all. I appreciate your help on getting the
$_POST variables to lower case and

Nov 21 '06 #9

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

Similar topics

4
by: Aaron W. West | last post by:
Timings... sometimes there are almost too many ways to do the same thing. The only significant findings I see from all the below timings is: 1) Integer math is generally fastest, naturally....
2
by: C L Humphreys | last post by:
Hi, Using a soundex function that works with anything except an empty/null string the following gives me an error part way through the results select surname, soundex(surname) from pd where...
2
by: Materialised | last post by:
Hi All, I have a problem. I have multiple text boxes on one form. When the user clicks in any of these text boxes, another (search) form opens which queries a database and returns the search...
6
by: Matej Cepl | last post by:
Hi, I am somehow experienced working with databases (mainly PostgreSQL on Linux) and with scripting (bash, Python, Basic), but total newbie when it comes to Access. However, in this temp job I...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
1
by: Chetana | last post by:
Hi All, I want the query in sql which gives count of records for 2 conditions. Say i have table Category which has CategoryID and SubCatID as 2 columns. Then suppose i want count for the...
2
by: tedpottel | last post by:
Hi, Write now I have code to read in a set of data from a surrey. Could I find out how many rows of data the query has, without adding to a counter each time I read a row? Also is there a way...
2
by: marybrown | last post by:
i will write the complete problem i am facing. Here is the input file i am using. sxoght: #query hit score probability qstart qend qorientation tstart tend matches mismatches...
2
by: Andy B | last post by:
How would you find out if a linq table has 0 rows in it? I have this code: NewsContext.V_News() '*** linq table to be tested for 0 rows Any ideas?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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.