Re: odd results when running this

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chip Wiegand wrote:
Okay, so I have got the php bits working in this web page but it is running 3 times every time the page loads, and I see no reason why (I have opened this page in two differant browsers). The code for the entire page is pasted below, it includes some calls to include files which are not included in this message of course (and this file is itself included in another file), the page can be seen at this address: http://www.simradusa.com/index-test.php
If anyone can see any reason for the script to run 3 times please let me know.
Thanks,
Chip
[snip]
<?
$sql="select * from hotspots";
$result = mysql_query($sql);
while ( $row = mysql_fetch_array($result)) { printf("<p><img src=\"hotspots/latest1.gif\" alt=\"%s\" title=\"%s\"></p><p class=\"footnote\">%s</p>", $row["alt-text"], $row["title-text"], $row["desc-text"]);
printf("<p><img src=\"hotspots/latest2.gif\" alt=\"%s\" title=\"%s\"></p><p class=\"footnote\">%s</p>", $row["alt-text"], $row["title-text"], $row["desc-text"]); printf("<p><img src=\"hotspots/latest3.gif\" alt=\"%s\" title=\"%s\"></p><p class=\"footnote\">%s</p>", $row["alt-text"], $row["title-text"], $row["desc-text"]);
} ?>

Looking at the page, and the code block - the code likely isn't running three times. You have 3 rows in the database, and in your while() loop, you print out the data for each row 3 times. You'll notice on the sidebar in the webpage you have essentially 9 'blocks' of news - they images for them loop (a b c, a b c, a b c) and the text for them repeats ( d d d , e e e , f f f ).


Change your loop to print just once, and have a counter that sets the image to load (and if the counter goes beyond 3 - either have it not display the image, or add more images :), or limit the query to only return the latest three (add "limit 0, 3" to the query) )

Cheers,
--
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux