Schlo_50 Posted November 22, 2007 Share Posted November 22, 2007 Hello, I have no errors but am looking for a solution to my idea. I have a template page with items being displayed on it and the idea is when a user clicks that item it's item id gets passed into the next page so that it can be compared against the flat file database and then when matched displayed the item information. I'll show you how i am displaying items on a page and then i'll show you the code i have developed so far to try and get the item id to pass pages and display the item details. function displaytab(){ $lines = file("usertabs.txt"); foreach ($lines as $line) { $data = explode("|", $line); if (current($data) == $_SESSION['userName']) { $name = next($data); $url = next($data); $id = next($data); $sitead = "http://localhost/books1/area/index.php"; $_SESSION['id'] = $id; ?> <link href="style.css" rel="stylesheet" type="text/css" /> <table width="237" background="images/tab.png" border="0" cellpadding="1" cellspacing="0" class="main"> <tr> <td width="58"><div align="left"><a href="?id=view&&<?php echo "$id";?>"><?php echo "$name"; ?></a></div></td> <td width="175" class="main"><div align="right"><a href="?id=display"><img src="../images/edit.png" width="25" height="25" border="0" /></a> <a href="?id=del"><img src="../images/del.png" width="25" height="25" border="0" /></a></div></td> </tr> </table> <?php } } } This is view.php: <?php $tabid = $_GET['id']; $lines = file("usertabs.txt"); foreach($lines as $Key => $val) { $data[$key] = explode("|", $val); $user = ($data[$Key][0]); $name = ($data[$Key][1]); $url = ($data[$Key][2]); $id2 = ($data[$Key][3]); echo "$tabid"; if ($tabid == $id2) { echo "$user, $name, $url"; } } ?> This is my flat file database structure: Can anybody understand what im after? And what can be done to acheive it? Thanks very much! Quote Link to comment https://forums.phpfreaks.com/topic/78400-passing-data-into-generated-pages/ Share on other sites More sharing options...
trq Posted November 22, 2007 Share Posted November 22, 2007 Is there any reason your using flat files for this instead of a db? Quote Link to comment https://forums.phpfreaks.com/topic/78400-passing-data-into-generated-pages/#findComment-396743 Share on other sites More sharing options...
Schlo_50 Posted November 22, 2007 Author Share Posted November 22, 2007 Theres not a long list of reasons and i know mySQL is better, i just wanted a project which entailed flat files i guess. Quote Link to comment https://forums.phpfreaks.com/topic/78400-passing-data-into-generated-pages/#findComment-396749 Share on other sites More sharing options...
trq Posted November 22, 2007 Share Posted November 22, 2007 Seems your just making alot of work for yourself for no apparent reason. Anyway, what not working? I would do it like... <?php if (isset($_GET['id'])) { $tabid = $_GET['id']; $lines = file("usertabs.txt"); foreach ($lines as $line) { $parts = explode("|", $line); if ($tabid == $parts[3]) { echo "{$parts[0]}, {$parts[1]}, {$parts[2]}"; } } } ?> But its no different to your code really. Quote Link to comment https://forums.phpfreaks.com/topic/78400-passing-data-into-generated-pages/#findComment-396763 Share on other sites More sharing options...
Schlo_50 Posted November 22, 2007 Author Share Posted November 22, 2007 Ahh cool, well i had the right kind of idea then! I am a php noob, so even if it is the long way i am still learning things. I will try that code out and see what happens. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/78400-passing-data-into-generated-pages/#findComment-396765 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.