Solved

getting the quotes right

Posted on 2009-03-30
6
194 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Router for PHP reqeusts 12 32
Not needed 13 54
Apostophes in PHP generated form 6 13
AWS CLI - Instances, Volumes & Tagging 2 12
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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now