Solved

getting the quotes right

Posted on 2009-03-30
6
197 Views
Last Modified: 2013-12-12
I have the following php code - and I can't figure out how to properly "code" the output. Can someone help me get the quotes in the right place. I have veriified that my query is working and I manually coded the div "img1" (from a css file) so I know it works, but I can't seem to format the database output correctly.


<?php
 
$num_displayed = 5 ;
 
$rs = mysql_query("SELECT * FROM advertisers ORDER BY RAND() LIMIT $num_displayed"); 
 
while ($r = mysql_fetch_assoc($rs)) 
{
<div id="img1"><a href="http://"$r['webaddress']><img src="imagefolder/"$r['ImageName'] alt=$r['AdvName'] width="241" height="160" target="_blank" /></a>;
</div>
}
?>

Open in new window

0
Comment
Question by:mgerney
[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
  • 3
  • 2
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24018511
small changes:
<?php
 
$num_displayed = 5 ;
 
$rs = mysql_query("SELECT * FROM advertisers ORDER BY RAND() LIMIT $num_displayed"); 
 
while ($r = mysql_fetch_assoc($rs)) 
{
  print "<div id=\"img1\"><a href=\"http://" . $r['webaddress']. "><img src=\"imagefolder/" . $r['ImageName'] . " alt=" . $r['AdvName'] . " width=\"241\" height=\"160\" target=\"_blank\" /></a></div>";
}
?> 

or 
<?php
 
$num_displayed = 5 ;
 
$rs = mysql_query("SELECT * FROM advertisers ORDER BY RAND() LIMIT $num_displayed"); 
 
while ($r = mysql_fetch_assoc($rs)) 
{
  print '<div id="img1"><a href="http://' .$r['webaddress']. '><img src="imagefolder/'.$r['ImageName'] .' alt="' + $r['AdvName'] '" width="241" height="160" target="_blank" /></a></div>';
}
?>

Open in new window

0
 
LVL 6

Expert Comment

by:djberriman
ID: 24018517
I would think you would want

<div id="img1"><a href="http://$r['webaddress']"><img src="imagefolder/$r['ImageName']" alt="$r['AdvName']" width="241" height="160" target="_blank" /></a>;
</div>
0
 

Author Comment

by:mgerney
ID: 24019833
I got the following:

From angelIII's solution

Parse error: parse error in C:\wamp\www\CNDining\PHP\restbycity.php on line 1507

From djberriman solution:

Parse error: parse error in C:\wamp\www\CNDining\PHP\restbycity.php on line 1508

I will try both again to be sure I cut & pasted correctly - I must be doing something wrong!

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 6

Expert Comment

by:djberriman
ID: 24020019
I would think angelIII's solution should work.

print "<div id=\"img1\"><a href=\"http://" . $r['webaddress']. "><img src=\"imagefolder/" . $r['ImageName'] . " alt=" . $r['AdvName'] . " width=\"241\" height=\"160\" target=\"_blank\" /></a></div>";

although it could do with another set of quotes around the alt and one to end  the src and href tags I think. That should not make it fail with a parse error though.

print "<div id=\"img1\"><a href=\"http://" . $r['webaddress']. "\"><img src=\"imagefolder/" . $r['ImageName'] . "\" alt=\"" . $r['AdvName'] . "\" width=\"241\" height=\"160\" target=\"_blank\" /></a></div>";


0
 
LVL 6

Accepted Solution

by:
djberriman earned 500 total points
ID: 24020034
perhaps there is a space missing after web address?

print "<div id=\"img1\"><a href=\"http://" . $r['webaddress'] . "\"><img src=\"imagefolder/" . $r['ImageName'] . "\" alt=\"" . $r['AdvName'] . "\" width=\"241\" height=\"160\" target=\"_blank\" /></a></div>";
0
 

Author Closing Comment

by:mgerney
ID: 31564311
Thanks so much - I have spentmany hours trying to get this right (as you can tell I'm new at this) - it probably was the space after webaddress because I cut and pasted right from your code and it worked perfectly.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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