SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't automatically use phone number in query

    I can not get this to work. I have phone numbers stored in a varchar() field as 123-456-7890. I can pull that information out, but it is not recognized when I sent a query to another table.

    I have echo'ed what I am doing and the data is being pulled out.
    Example: echo $row['phone'] will print out the number.

    When I submitt the data as a variable in a query is does not find records that are there. I have tried:

    $dups = "
    SELECT email, username FROM user
    WHERE phone1 like '{$row['email']}'
    ";

    I have tried to put the mysql_fetch_assoc() data into a simpler variable as $fon and it still is not found.

    $dups = "
    SELECT email, username FROM user
    WHERE phone1 like '{$fon}'
    ";

    The only way I can get it to work is to directly assign the value in a line as:

    $row['email'] = '123-456-7890';
    or
    $fon = '123-456-7890';

    This I can not do with over 1200 numbers. I need to be able to pull it from the table and use it to query another table. I also tried stripslashes() thinking that might have something to do with it.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,015
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by NevadaSam View Post
    This I can not do with over 1200 numbers. I need to be able to pull it from the table and use it to query another table.
    what you want is a join query

    this will avoid "pulling it" from a table and "using it" to query another table

    everything is done with a single query
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I should have thought of that.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •