[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

getting the quotes right

Posted on 2009-03-30
6
Medium Priority
?
201 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

656 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