The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
using the where syntax for a query to a mysql server
Discuss using the where syntax for a query to a mysql server in the Perl Programming forum on Dev Shed. using the where syntax for a query to a mysql server Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 21st, 2000, 07:38 PM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: USA
Posts: 67
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Hello, i am tryint to use the following string
$sql_query="select * from tableName where fieldName = 12345";
I want to return the record where fieldname=12345.
WHen i do this, i get no dataa, but i know that there is data matching that criteria, could someone help ?
|

March 22nd, 2000, 09:58 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
|
David,
Is your field a varchar type???.
If it is a varchar type then you should use
$sql_query="SELECT * FROM tableName WHERE fieldName = '12345'";
|

March 22nd, 2000, 08:06 PM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: USA
Posts: 67
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Shiju,
sorry about taht, i forgot to metion the type of data.
I am searching for an interger, but if you could give me some popular examples, i would appreciate it.
Btw, the example you gave was great, how would i do it w/ a variable.,...like this?
$sql_query="SELECT * FROM tableName WHERE fieldName=$criteria";
Thanks
|

March 22nd, 2000, 11:42 PM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
Hi David,
Your synatx is correct.
i am writing one example here:
"SELECT article, dealer, price
FROM shop
WHERE price=19.95"
Table name and field name shd be case sensitive.
Is your simple select statement is working??.
---------
$sql_query="SELECT * FROM tableName WHERE fieldName=$criteria";
after this query just try to print query to screen so we can make sure that value is passing to query.
print $sql_query;
just check it out for more select statement in mysql online mannual.
i tried to see your profile but i couldn't see anything.Where are you working??.
You may see my personel info at:
http://208.56.74.76/
|

March 23rd, 2000, 08:29 AM
|
|
Junior Member
|
|
Join Date: Mar 2000
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
This works no matter what field type, and is the best way to go always:
$scaler = 12345;
$sql_query = $dbh->prepare ("SELECT * FROM tableName WHERE fieldName = ?");
$sql_query->execute ($scaler);
|

March 28th, 2000, 06:19 PM
|
|
Contributing User
|
|
Join Date: Jan 2000
Posts: 108
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
bydavid,
You may know this already, but if it is a variable you want to add to the query, I found something like this to work fine:
$sql_query="SELECT * FROM tableName WHERE fieldName=".$criteria; (INSTEAD OF)
$sql_query="SELECT * FROM tableName WHERE fieldName=$criteria";
If you are still not receiving data, make sure that your fetchrow() command is correct. Another option is to print the sql query, as stated above, and run it through SSH or telenet. What response do you get?
Good Luck http://www.datera.com
|

March 29th, 2000, 01:01 AM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: USA
Posts: 67
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Yoshi...
what does the .$varname do?
|

March 29th, 2000, 07:20 PM
|
|
Contributing User
|
|
Join Date: Jan 2000
Posts: 108
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
bydavid,
I have found that
$sql_query="SELECT * FROM tableName WHERE fieldName=$criteria";
Searches for where the fieldName equals "$criteria". If you want to search for the value contained inside of $criteria, I would recommend using this:
$sql_query="SELECT * FROM tableName WHERE fieldName=".$criteria;
This is like searching for:
$sql_query="SELECT * FROM tableName WHERE fieldName=12345"; (if 12345 is the value of the variable)
Good Luck! http://www.datera.com
|

March 30th, 2000, 11:59 PM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: USA
Posts: 67
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Yoshi
i havent used perl for too long so i maybe completely wrong, but isnt that what a variable is supposed to do ? a variable contains data right, so when you add the period, isnt that repetitive then?
like i said, im not too experience with perl, so if you could clarify, i woudl appreciate it
thanks
|

March 31st, 2000, 06:19 PM
|
|
Contributing User
|
|
Join Date: Jan 2000
Posts: 108
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
bydavid,
You are right. A call with the variable inside of the parenthises is the same as a call to the variable using a dot. Both refer to the data inside of the variable. For example:
$sql_query="SELECT * FROM tableName WHERE fieldName=$criteria";
Is the same as
$sql_query="SELECT * FROM tableName WHERE fieldName=".$criteria;
It's not repetive to use the dot. If you were searching (and $criteria equals 12345), the actual search will turn out like this:
$sql_query="SELECT * FROM tableName WHERE fieldName=12345";
Using one of the commands above (both work)
Good Luck! http://www.datera.com
|

April 1st, 2000, 05:56 PM
|
|
Contributing User
|
|
Join Date: Mar 2000
Location: USA
Posts: 67
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
okay, thanks.
i think i have a better understanidng now.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|