Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts

    simple concantination problem? (think i spelt it right)

    Hi All,

    Well hopefully you understand what im going on about,

    i have a query in my php
    PHP Code:
        $value_query "Select * FROM ratings WHERE id = '$idReference'"
    idreference prints out test
    but how do i change the above query to add the word total directly after the value of idreference?

    so i get testvalue print out.

    so i tried
    PHP Code:
        $value_query "Select * FROM ratings WHERE id = '"$idReference"'.test"
    but i was getting an unexpected T_VARIABLE error.

    p.s i havent included the rest of the code for this query as this is the incorrect part

    any ideas
    Cheers

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Take a look at the MySQL CONCAT() function.

    And, btw, it's "concatenation" (only because you asked).

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hiya pappajohn,

    i was close lol, im surprised i was that close to be honest

    will check out the link thanks
    Luke

  • #4
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Thumbs up

    You can't do that AFAIK(as far as I know)
    PHP Code:
    $value_query "Select * FROM ratings WHERE id = '$idReference'";
    $result mysql_query($value_query) or die(mysql_error());
    $row_result mysql_fetch_assoc($result);
     
    //now you use your concatenation
    echo $row_result['field']."test"
    Cheers

    You need basic PHP training first.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hi student101,

    thanks for your reply, im sure it can be done, i've done it before but i cant find it

    cheers

  • #6
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by LJackson View Post
    im sure it can be done, i've done it before but i cant find it
    What can be done?
    What are you looking to do?
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    Hi,

    i want to have my query to match all records in my database where id equals the value of idReference plus the word value.

    e.g idReference = "time", so i want to search the database for everything that matches "timevalue"

    im sure this can be done by using concatenation to add the word value to the idReference

    something like
    PHP Code:
    $value_query "Select * FROM ratings WHERE id = '"$idReference"'.test"
    cheers

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    @ pappa john,

    i have looked through the info but its a load of gobeldy goop

    i tried
    PHP Code:
    $value_query "Select * FROM ratings WHERE id = CONCAT($idReference,test)"
    but im getting Warning: mysql_fetch_array()

    any ideas
    thanks
    Luke

  • #9
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    PHP Code:
    $value_query "Select * FROM ratings WHERE id = '$idReference' AND WHERE id LIKE %somevlaue%";
    $result mysql_query($value_query) or die(mysql_error());
    $row_result mysql_fetch_assoc($result);
     
    //now you use your concatenation
    echo $row_result['field']."test"

    OR
    PHP Code:
    $value_query "Select * FROM ratings WHERE id = '$idReference' OR WHERE id LIKE %somevlaue%";
    $result mysql_query($value_query) or die(mysql_error());
    $row_result mysql_fetch_assoc($result);
     
    //now you use your concatenation
    echo $row_result['field']."test"

    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    Hi student101,

    i see what your saying but i need my query to check for the value of idReference plus "value".

    so what i have done is
    PHP Code:
        $storerating $idReference."value"
    then used $storerating in my query as such
    PHP Code:
        $value_query "Select * FROM ratings WHERE id = '$storerating'"
    which works

    thanks for your help
    Luke

  • #11
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Anytime.

    Cheers
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #12
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by LJackson View Post
    Hi student101,

    i see what your saying but i need my query to check for the value of idReference plus "value".

    so what i have done is
    PHP Code:
        $storerating $idReference."value"
    then used $storerating in my query as such
    PHP Code:
        $value_query "Select * FROM ratings WHERE id = '$storerating'"
    which works

    thanks for your help
    Luke
    You don't really need that extra variable.

    PHP Code:
        $value_query "Select * FROM ratings WHERE id = '$idReference"."value'"


  •  

    Posting Permissions

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