Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 21st, 2000, 07:38 PM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 ?
Comments on this post
JimmyGosling agrees!

Reply With Quote
  #2  
Old March 22nd, 2000, 09:58 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
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'";






Reply With Quote
  #3  
Old March 22nd, 2000, 08:06 PM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old March 22nd, 2000, 11:42 PM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
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/


Reply With Quote
  #5  
Old March 23rd, 2000, 08:29 AM
RUSTY RUSTY is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 1 RUSTY User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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);

Comments on this post
JimmyGosling agrees!

Reply With Quote
  #6  
Old March 28th, 2000, 06:19 PM
yoshi yoshi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 108 yoshi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Send a message via ICQ to yoshi
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

Reply With Quote
  #7  
Old March 29th, 2000, 01:01 AM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Yoshi...

what does the .$varname do?

Reply With Quote
  #8  
Old March 29th, 2000, 07:20 PM
yoshi yoshi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 108 yoshi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Send a message via ICQ to yoshi
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

Reply With Quote
  #9  
Old March 30th, 2000, 11:59 PM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #10  
Old March 31st, 2000, 06:19 PM
yoshi yoshi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 108 yoshi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Send a message via ICQ to yoshi
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

Reply With Quote
  #11  
Old April 1st, 2000, 05:56 PM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
okay, thanks.

i think i have a better understanidng now.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > using the where syntax for a query to a mysql server

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap