EternalSorrow Posted November 16, 2009 Share Posted November 16, 2009 I'm currently setting up a page which _GETs the $id (here called $fid) from a table (simple, right?), but I've found a large problem. The include.php (here called banner.php) has a $query statement which also pulls information from the same table. Whenever I try to click on one of the items listed from the table (here called $film), the information which comes up is always that of the last $row in the table. Here's an example: FILM 1 2 3 clicked on $film link with $id 2 --> information shown from --> $id 3 I know it's a particular script in the banner.php include because I tried deleting the snippet and the problem disappeared. The URL shows the correct $fid, but the script in the page.php isn't pulling the $fid from there, but from the script in the banner.php include file. What I'm curious to know is what exactly the problem is ($query not closed properly or something similar?) and how to solve the problem (mysql_close or something similar?). Here's the code in the banner.php which is causing the interference: <?php mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query = "SELECT title, image, fid, datetime, NULL AS occupation, year, 'film' AS table1 FROM film UNION ALL SELECT name, img, id, occupation, datetime, NULL, 'people' FROM people ORDER BY datetime DESC LIMIT 5"; $result = mysql_query( $query ) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { extract($row); if ($row['table1'] == 'film') echo '<li><a href="filmography.php?fid='.$id.'"><img src="images/thumbnails/'.$image.'.jpg" alt="" title="'.$title.' ('.$year.')"></a></li>'; if ($row['table1'] == 'people') echo '<li><a href="biography.php?id='.$fid.'"><img src="images/thumbnails/'.$image.'.jpg" alt="" title="'.$title.' ('.$occupation.')"></a></li>'; } ?> And here's the code in the page.php which is interfered with: <?php if (!is_numeric($_GET["fid"]) && !empty($_GET["fid"]) && $_GET["fid"]!="") { $fid = $_GET["fid"]; } mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query = "SELECT fid, title, year, info, image FROM film WHERE `fid` = '$fid' "; $result = mysql_query( $query ) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); $text=preg_replace('/\W.*/','',$title); $string = "$title"; $words = str_word_count($string, 1); array_shift($words); if(preg_match('/\s/',$row['title'])) { $space = ' '; } else { $space = ''; } echo '<h3><span id="film">'.$text.'</span>'; echo implode(' ', $words); echo ''.$space.'('.$year.')</h3> <div class="boxgrid captionfull" style="float: right; margin: 0px 0px 8px 8px;"> <img src="images/thumbnails/'.$image.'.jpg" alt=""> <div class="cover boxcaption"> <div style="margin: 0px 4px 0px 4px;">'.$title.' ('.$year.')</div> </div> </div> '.$info.''; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.