Welcome to WebmasterWorld Guest from 54.227.1.130

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

issue with href links using while loop

     

tsafford

8:24 pm on Mar 16, 2010 (gmt 0)

5+ Year Member



<? $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.

Matthew1980

8:47 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi there tsafford,

Welcome to the forum ;-p

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

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

Secondly

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());

Thirdly

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

Fourthly

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.
print_r($row);
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?

if(isset($_GET['film_id']))
{
$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,

Cheers,
MRb

gsmith

8:48 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month