Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL CONCAT problems

Posted on 2013-01-25
2
Medium Priority
?
334 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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