homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

using while loop to create href links all work but the first
issue with href links using while loop

Msg#: 4099035 posted 8:24 pm on Mar 16, 2010 (gmt 0)

<? $sql = "select * from film_shows ORDER BY film_order asc";
$res = mysql_query($sql);
//$row = mysql_fetch_array($res);

while($row = mysql_fetch_array($res)) {
if($row) {
$film_title = $row['film_title'];
$film_picture = $row['film_picture'];
$film_shdes = $row['film_shdes'];
$film_id = $row['film_id'];

$result = "<div id=\"content_reality\">";
$result .= "<h2>";
$result .= "".$row['film_title']."";//$film_title;
$result .= "</h2>";
$result .= "<p align=\"justify\" style=\"min-height:200px;\">";
$result .= "<img src=\"".$row['film_picture']."\"align=\"left\" style=\"clear:both; max-width:150px; max-height:150px; padding-left: 20px;padding-right: 20px;\" alt=\"\" border=\"0\">";
$result .= "".$row['film_shdes'].""; //$film_shdes;
$result .= "<br>";
$result .= "<a href=\"filmshow.php?film_id=".$row['film_id']."\">";
$result .= "Learn More";
$result .= "</a></p>";
$result .= "</div>";
echo $result;


This is my current code.

I does what I want and pulls information from the database and puts them on the page, the only issue is that the link to the first page doesn't work, while all the rest of them do. I have changed this code a few times, but still the first link will not work.

Any help would be appreciated.



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4099035 posted 8:47 pm on Mar 16, 2010 (gmt 0)

Hi there tsafford,

Welcome to the forum ;-p

Well as its advice you after I will try my best..

Always use the full tags as not all servers support short tags, <?php


When querying the DB always put (in bold) on the end, this then can be used to see what errors are being thrown from the DB side of things, though you need to make sure that when you go public its removed, this is good practise to do as leaving it on gives info to hackers if things go wrong.

$res = mysql_query($sql)or die(mysql_error());


//If the connection is good process and build the page
while($row = mysql_fetch_array($res))
{//build page now
echo "An error has occured, please try again later";


as the while() is being processed:-

while($row = mysql_fetch_array($res))
//print the $row array to check as the data in the keys are right, ie as expected.
exit;// Just use this to kill the script

I know this sounds silly but have you looked at the page source to see what the value is that is now on the end of the link? And the file/page receiving the URL, is the $_GET asking for the right value?

$received_id = strip_tags($_GET['film_id']);

And is the file that the link points to in the same directory as the file sending the link ?

I know as this makes no difference but its good practice to form the sql string as it would be in the DB:-

$sql = "SELECT * FROM `film_shows` ORDER BY `film_order` ASC";

Just a few thoughts there for you.

Good luck with the project,



10+ Year Member

Msg#: 4099035 posted 8:48 pm on Mar 16, 2010 (gmt 0)

It sounds to me like there is a problem with the data itself (i.e. the value stored in the first row that's used to create that link).

BTW, the "if" that immediately follows the "when" is redundant.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved