...

View Full Version : simple concantination problem? (think i spelt it right)



LJackson
02-28-2009, 10:13 PM
Hi All,

Well hopefully you understand what im going on about,

i have a query in my php

$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

$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

PappaJohn
02-28-2009, 10:26 PM
Take a look at the MySQL CONCAT() (http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat) function.

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

LJackson
02-28-2009, 10:29 PM
hiya pappajohn,

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

will check out the link thanks
Luke

student101
02-28-2009, 10:30 PM
You can't do that AFAIK(as far as I know)

$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 (http://www.w3schools.com/PHP/DEfaULT.asP) first.

LJackson
02-28-2009, 10:35 PM
hi student101,

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

cheers

student101
02-28-2009, 10:38 PM
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?

LJackson
02-28-2009, 10:46 PM
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

$value_query = "Select * FROM ratings WHERE id = '"$idReference"'.test";

cheers

LJackson
02-28-2009, 10:49 PM
@ pappa john,

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

i tried

$value_query = "Select * FROM ratings WHERE id = CONCAT($idReference,test)";

but im getting Warning: mysql_fetch_array()

any ideas
thanks
Luke

student101
02-28-2009, 10:53 PM
$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

$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";

LJackson
02-28-2009, 11:13 PM
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

$storerating = $idReference."value";


then used $storerating in my query as such

$value_query = "Select * FROM ratings WHERE id = '$storerating'";


which works :)

thanks for your help
Luke

student101
03-01-2009, 06:49 AM
Anytime.

Cheers

tosbourn
03-03-2009, 05:45 PM
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

$storerating = $idReference."value";


then used $storerating in my query as such

$value_query = "Select * FROM ratings WHERE id = '$storerating'";


which works :)

thanks for your help
Luke

You don't really need that extra variable.


$value_query = "Select * FROM ratings WHERE id = '$idReference"."value'";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum