|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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 ? |
|
#2
|
||||
|
||||
|
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'"; |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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/ |
|
#5
|
|||
|
|||
|
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); |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
Yoshi...
what does the .$varname do? |
|
#8
|
|||
|
|||
|
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 |
|
#9
|
|||
|
|||
|
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 |
|
#10
|
|||
|
|||
|
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 |
|
#11
|
|||
|
|||
|
okay, thanks.
i think i have a better understanidng now. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > using the where syntax for a query to a mysql server |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|