[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

getting the quotes right

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
mgerney
Asked:
mgerney
  • 3
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
djberrimanCommented:
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
 
mgerneyAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
djberrimanCommented:
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
 
djberrimanCommented:
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
 
mgerneyAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now