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
https://forums.phpfreaks.com/topic/78400-passing-data-into-generated-pages/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.