#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    USA
    Posts
    67
    Rep Power
    15
    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
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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'";





  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    USA
    Posts
    67
    Rep Power
    15
    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
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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/

  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    1
    Rep 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
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    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
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    USA
    Posts
    67
    Rep Power
    15
    Yoshi...

    what does the .$varname do?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    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
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    USA
    Posts
    67
    Rep Power
    15
    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
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    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
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    USA
    Posts
    67
    Rep Power
    15
    okay, thanks.

    i think i have a better understanidng now.

IMN logo majestic logo threadwatch logo seochat tools logo