PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
sarris
Forum Contributor
Posts: 137 Joined: Mon Dec 04, 2006 2:44 pm
Post
by sarris » Thu Apr 12, 2007 12:51 pm
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
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Thu Apr 12, 2007 12:59 pm
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])
sarris
Forum Contributor
Posts: 137 Joined: Mon Dec 04, 2006 2:44 pm
Post
by sarris » Thu Apr 12, 2007 1:06 pm
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?
sarris
Forum Contributor
Posts: 137 Joined: Mon Dec 04, 2006 2:44 pm
Post
by sarris » Thu Apr 12, 2007 1:10 pm
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
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Thu Apr 12, 2007 1:10 pm
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
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Thu Apr 12, 2007 1:16 pm
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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Apr 12, 2007 2:01 pm
Always always always quote strings. Always.
sarris
Forum Contributor
Posts: 137 Joined: Mon Dec 04, 2006 2:44 pm
Post
by sarris » Thu Apr 12, 2007 5:50 pm
ok!thanks everybody for the useful tips