Solved

getting the quotes right

Posted on 2009-03-30
6
196 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
  • 3
  • 2
6 Comments
 
LVL 142

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
paypal ipn to mysql 3 41
send post values 7 26
Logic behind "best rated" calculation 11 23
parse url to form? 7 15
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

825 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