Solved

MySQL CONCAT problems

Posted on 2013-01-25
2
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38819719
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
ID: 38819737
Spot on!
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

615 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