Solved

MySQL CONCAT problems

Posted on 2013-01-25
2
322 Views
Last Modified: 2013-01-25
I am trying to output the results of this query.  I have been playing around with it all day.  I am getting results except for the CONCAT field, Here is the query.

$query="SELECT tblRestaurants.RestName,
CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street)
FROM tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
	WHERE tblLocations.CuisineID='$Doggie'
	GROUP BY tblLocations.RestID and tblRestaurants.RestName
	ORDER BY tblRestaurants.RestName ASC";

Open in new window


and the results...
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"RestName");
$f2=mysql_result($result,$i,"[CONCAT(tblLocations.StreetNumber,'  ', tblLocations.Street)]");
?>

Open in new window


It has to be in the syntax?
0
Comment
Question by:DS928
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
you have to give the expression an alias, and use the alias in php:
$query="SELECT tblRestaurants.RestName,
CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) street_info
FROM tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
	WHERE tblLocations.CuisineID='$Doggie'
	GROUP BY tblLocations.RestID and tblRestaurants.RestName
	ORDER BY tblRestaurants.RestName ASC";

Open in new window

and then:
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"RestName");
$f2=mysql_result($result,$i,"street_info");
?>

Open in new window


http://www.experts-exchange.com/Database/Miscellaneous/A_11135-Why-should-I-use-aliases-in-my-queries.html
0
 

Author Closing Comment

by:DS928
Comment Utility
Spot on!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now