Solved

MySQL CONCAT problems

Posted on 2013-01-25
2
326 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code planning methods/tools? 5 56
emailing registered email addresses in phpmyadmin 5 69
Google Recaptcha 13 52
php mail() send emails but the message is lost 4 33
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

739 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