Jump to content

Passing data into generated pages


Schlo_50

Recommended Posts

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:

 

39113942zd7.jpg

 

Can anybody understand what im after? And what can be done to acheive it?

 

Thanks very much!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.