Page 1 of 1

dot " . "character in concentrated strings

Posted: Thu Apr 12, 2007 12:51 pm
by sarris
hi there. i am trying to echo the results of a sql query.

Code: Select all

$array_str  .= $row[Address] . "**" . $row[rent_price].  "**" . $row[Size] . "**" . $row[id] . "**" . $row[areas.name] . "**" . $row[beds_num] 
echo $array_str;
as obvious there is a problem with areas.name as the . is considered to be the concetration of the strings. How can i correct this?
thanks

Posted: Thu Apr 12, 2007 12:59 pm
by aaronhall
Is "areas.name" the qualified column name in the table? $row['name'] should work unless your query has a reference to a column of the same name and in a different table. You can always assign an alias to the column in the query, like:

Code: Select all

SELECT areas.name as areaName ....
$row['areaName'] would refer to that column.

Also, you should be quoting array indices as not to confuse PHP ($row['Address'] instead of $row[Address])

Posted: Thu Apr 12, 2007 1:06 pm
by sarris
This is my query.

Code: Select all

$sql = "SELECT Address,
 	        $lookin.id,
 	        Size,
 	        rent_price,
 	        areas.name,
 	        beds_num,
 	        coords_X,
 	        coords_Y
		FROM $lookin,areas
		WHERE $lookin.area_id = areas.id AND $lookin.rent = 1";
name exists is another table as well...
It works pretty fine without the ' '
My question is more about string concentration...how to i include the dot (" . ") character into a concentrated string?

Posted: Thu Apr 12, 2007 1:10 pm
by sarris
added the AS clause and works ok.
Thanks...
however i still have the wondering...how to add the dot character into a string
thanks again

Posted: Thu Apr 12, 2007 1:10 pm
by aaronhall
sarris wrote:name exists is another table as well...
[s]Add an alias for the column as I suggested[/s] you beat me to it :)
sarris wrote:It works pretty fine without the ' '
If you change your error_reporting() to E_ALL, you'll find that it's not
sarris wrote:My question is more about string concentration...how to i include the dot (" . ") character into a concentrated string?
Not sure what you mean

Posted: Thu Apr 12, 2007 1:16 pm
by Begby
You need to quote your strings, this is a must and this is why $row[areas.name] is not working. This would work $row['areas.name'].

Secondly to contactenate a '.' into a string just put it in quotes like this

Code: Select all

$fname = 'fred' ;
$lname = 'flinstone' ;
echo $fname.'.'.$lname ;
// echos fred.flinstone

Posted: Thu Apr 12, 2007 2:01 pm
by RobertGonzalez
Always always always quote strings. Always.

Posted: Thu Apr 12, 2007 5:50 pm
by sarris
ok!thanks everybody for the useful tips