Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Making a line break, MySQL and PHP

Posted on 2013-01-27
8
Medium Priority
?
527 Views
Last Modified: 2013-01-27
I am running a query in MySQL and PHP.  THe query worrked until I needed to put Name and Address on two different lines, can't seem to find out how it works.  Here is the code.

$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"RestName<br/>Address");
$f2=mysql_result($result,$i,"Phone");
$f3=mysql_result($result,$i,"Price");
$f4=mysql_result($result,$i,"Rating");

Also if it matters address is the result of  a CONCAT.

Open in new window

0
Comment
Question by:DS928
  • 5
  • 3
8 Comments
 
LVL 16

Expert Comment

by:kmslogic
ID: 38825447
the mysql_result() function is expecting a column name--so Name and Address should be two separate columns in your query and then in your processing to output them you should worry about putting them on two separate lines.

If you show the code above this section that does your query I can give some more specifics.
0
 

Author Comment

by:DS928
ID: 38825451
Thank you.  This is the query.

$query="SELECT tblLocations.CityID, tblLocations.AreaID, tblLocations.CuisineID, tblRestaurants.RestName, 			 	
		CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) Address,
		tblLocations.Phone, tblDetails.Price,tblDetails.Ratings
		FROM tblRestaurants
		INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID
		INNER JOIN tblDetails ON tblLocations.RestID = tblDetails.RestID AND tblLocations.LocationID = 	tblDetails.LocationID
		WHERE tblLocations.CityID='$Doggie'
		AND tblLocations.AreaID='$Kitty'
		AND tblLocations.CuisineID='$Pig'
		ORDER BY tblRestaurants.RestName ASC";

Open in new window

0
 
LVL 16

Expert Comment

by:kmslogic
ID: 38825465
Ok, so in this section it should look something like this:

$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"RestName");
$f2=mysql_result($result,$i,"Address");
$f3=mysql_result($result,$i,"Phone");
$f4=mysql_result($result,$i,"Price");
$f5=mysql_result($result,$i,"Rating");

Open in new window


And then you should handle showing $f1 and $f2 on separate lines in your output code (if you show me your output echo statements I can give you some idea there too).

Also, if this address query is working then you can ignore this but I normally see this line of your query like this:

CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) AS Address

Open in new window


(note the AS)
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:DS928
ID: 38825468
Here is the output.
<tr>
      <td bgcolor="#FFDAA6">&nbsp;</td>
      <td width="325"><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
      <td width="150"><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
      <td width="100"><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
      <td width="100"><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
    </tr>

Open in new window


Its should print like this.

Name
Address

Not like this..
Name     Address
0
 
LVL 16

Accepted Solution

by:
kmslogic earned 2000 total points
ID: 38825481
Ok, so assuming you want the name and address to appear in the first cell of the table on separate lines:

<tr>
	<td bgcolor="#FFDAA6">&nbsp;</td>
	<td width="325"><font face="Arial, Helvetica, sans-serif"><?php echo $f1 . "<br />" . $f2; ?></font></td>
	<td width="150"><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
	<td width="100"><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
	<td width="100"><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
</tr>

Open in new window

0
 

Author Comment

by:DS928
ID: 38825488
OK, thank you. the errors are finally gone, but I am not receiving an output anymore.

<td width="325"><font face="Arial, Helvetica, sans-serif"><?php echo $f1 . "<br />" . $f2; ?></font></td>

Open in new window


HOK I rem out the output line for Name Address and I get these two errors.....I assume the second is because of the first.

Warning: mysql_result() [function.mysql-result]: RestName<br/>Address not found in MySQL result index 3 in /home/content/d/s/t/dstr3/html/MENUHEAD/Steelers/result_city.php on line 173
 
Warning: mysql_result() [function.mysql-result]: Rating not found in MySQL result index 3 in /home/content/d/s/t/dstr3/html/MENUHEAD/Steelers/result_city.php on line 176
0
 

Author Comment

by:DS928
ID: 38825506
Murphy's Law.  It's working!  Thank you for your help!
0
 

Author Closing Comment

by:DS928
ID: 38825507
Helped me out of that tricky syntax!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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. . .
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

879 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