Schlo_50 Posted December 3, 2007 Share Posted December 3, 2007 Can anybody help me in developing my sscript to pass variables through a URL? I have results echo'ed out onto a page and they are assigned a unique ID. When a link is clicked i want my display.php page to show all information about the link that was clicked. At the moment i have the categoryid at the end of my URL but when it links to display.php nothing but a blank screen is shown. Any ideas? function: function view($id){ $lines = file("usercats.txt"); foreach ($lines as $line) { $data[$key] = explode("|", $line); $user = trim($Data[$Key][0]); $catname = trim($Data[$Key][1]); $id = trim($Data[$Key][2]); $_SESSION['id'] = $id; print '<a href="display.php?id='.$_SESSION['id'].'">$catname</a><br />'; } } display.php <?php if(isset($_GET['id'])){ $id = (int) $_GET['id']; //type casting - only want integers for our ID. This would prevent any SQL injection attack }else{ echo 'The Category information could not be found!'; exit; } $file = file("usercats.txt"); foreach($file as $Key => $Val){ $Data[$Key] = explode("|", $Val); $loop_id = $Data[$Key][1]; if($loop_id == $id){//each time the loop runs, check if it is the ID we are looking for if it is display the info $username = $Data[$Key][0]; $thumbid = $Data[$Key][2]; $title = $Data[$Key][3]; $desc = $Data[$Key][4]; $date = $Data[$Key][5]; //print out the information print $username; print $loop_id; print $thumbid; print $title; print $desc; print $date; break;//once found, we can exit out of our foreach loop } } ?> Thanks for any help, suggestions, code snippets or tutorials! Quote Link to comment Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 According to your view() function, every link will have the same id value, that of the current users $_SESSION['id'], surely you would want this to be some sort of record id? Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 3, 2007 Author Share Posted December 3, 2007 Yes, your right. 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.