Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying relative info in new window?

Status
Not open for further replies.

overyde

Programmer
Joined
May 27, 2003
Messages
226
Location
ZA
Hi,
I'm using php4 and apache 2. I need to display additional information in a seperate window according to a fieldset that is selected from a table. I was thinking of using session variables(as below) but it either repeats one of the fieldsets repeatedly or shows the same info no matter what link image(which is the link to data.php) I click on.
I also had to paginate my results which is where I think the problems are coming in.
The 2 php pages (view.php and data.php) are below.
Any ideas?

**************************************************
VIEW.PHP
**************************************************

<?
session_start();

define(MAX_DISPLAY, 2);

$link = mysql_connect(&quot;localhost&quot;, &quot;&quot;, &quot;&quot;)
or die(&quot;Could not connect : &quot; . mysql_error());

mysql_select_db(&quot;online&quot;)
or die(&quot;Could not select database&quot;);

printf(&quot;<br>Row Start: %d Next Row: %d<br><br>\n&quot;, $_GET[page], $_GET[page]+MAX_DISPLAY);
if(!$_GET[page]) {
printf(&quot;<a href='view.php?page=%s'>Prev Page</a>&nbsp;&nbsp;&nbsp;&quot;, $prevpage);
printf(&quot;<a href='view.php?page=%s'>Next Page<br><br></a>&quot;, ($_GET[page] + MAX_DISPLAY));
$query = &quot;select cat, sub, vname, vtel, vaddress, vote, specials, picture, pictureb from place limit &quot;.MAX_DISPLAY.&quot;&quot;;
} else {
$query = &quot;select cat, sub, vname, vtel, vaddress, vote, specials, picture, pictureb from place limit &quot;.($_GET[page] - 1).&quot;,&quot;.MAX_DISPLAY.&quot;&quot;;
$prevpage = ($_GET[page] - MAX_DISPLAY);
$_GET[page] = ($_GET[page] + MAX_DISPLAY);
printf(&quot;<a href='view.php?page=%s'>Prev Page</a>&nbsp;&nbsp;&nbsp;&quot;, $prevpage);
printf(&quot;<a href='view.php?page=%s'>Next Page</a><br><br>&quot;, $_GET[page]);
}


$result = mysql_query($query)
or die(&quot;Could not complete query : &quot; . mysql_error());

if(!$result) {
printf(&quot;No entries found.\n&quot;);
exit;
}



print &quot;<table border=1><tr><th>Picture</th>&quot;;
print &quot;<th>Name</th><th>Category</th><th>sub</th><th>Specials</th><th>Address</th><th>Telephone</th><th>Vote Page</th></tr>&quot;;


// go through each row in the result set and display data
while ($newArray = mysql_fetch_array($result)) {
// give a name to the fields
$cat = $newArray['cat'];
$sub = $newArray['sub'];
$vname = $newArray['vname'];
$vtel = $newArray['vtel'];
$vaddress = $newArray['vaddress'];
$vote = $newArray['vote'];
$specials = $newArray['specials'];
$picture = $newArray['picture'];
$pictureb = $newArray['pictureb'];

//these are the session variables
$_SESSION[specials] = mysql_result($result, 0, 'specials');
$_SESSION[picture] = mysql_result($result, 0, 'picture');




//echo the results on screen
echo &quot;
<tr>
<td align=\&quot;center\&quot;><a href=\&quot;data.php\&quot; target=\&quot;blank\&quot;><img border=\&quot;0\&quot; src=\&quot;$picture\&quot;></a></td>
<td>$vname</td>
<td>$cat</td>
<td>$sub</td>
<td>The current specials are $specials.</td>
<td>We are situated at $vaddress</td>
<td>and you can get hold of us on $vtel.</td>
<td> <a href=\&quot;$vote\&quot; target=\&quot;blank\&quot;>Vote for us.</a></td>
</tr>&quot;;

//if authorized, get the values of f_name l_name and other details

$cat = mysql_result($result, 0, 'cat');
$picture = mysql_result($result, 0, 'picture');

//these are the session variables
$_SESSION[cat] = mysql_result($result, 0, 'cat');
$_SESSION[picture] = mysql_result($result, 0, 'picture');
}
print &quot;</table>&quot;;


mysql_free_result($result);
mysql_close($link);



?>
*********************************************
DATA.PHP
**********************************************

Reality is built on a foundation of dreams.
 
Correction:
We you see the cute little kitty under the session variables it should be &quot;cat&quot; in []

Reality is built on a foundation of dreams.
 
I'm using a new paginate script. Any help with possibly using a session variable...whatever to display the relative info in a seperate window (data.php).

VIEW.PHP
********************************
<?php
require('pagedresults.php');

$cnx = @mysql_connect('localhost','','');
mysql_select_db('online',$cnx);
$rs = new MySQLPagedResultSet(&quot;select * from place&quot;, 1,$cnx);
?>

<html>
<head>
<title>Paged Results Demo</title>
</head>
<body>

<table border=&quot;1&quot;>
<?php
while ($row = $rs->fetchArray()):

?>

<tr>
<td width=&quot;100&quot;>
<?=$row['user']?>
</td>

<td width=&quot;100&quot;>
<a href=&quot;data.php&quot; target=&quot;_blank&quot;><img src=&quot;<?=$row['picture']?>&quot;></a>
</td>
</tr>

<?php
endwhile;
?>

<tr>
<td align=&quot;center&quot; colspan=&quot;2&quot;>
<?=$rs->getPageNav(&quot;aid=$aid&quot;)?>
</td>
</tr>
</table>

<p>

</p>
</body>
</html>

PAGEDRESULTS.PHP
*******************************************
<?php

class MySQLPagedResultSet
{

var $results;
var $pageSize;
var $page;
var $row;

function MySQLPagedResultSet($query,$pageSize,$cnx)
{
$resultpage = $_GET['resultpage'];

$this->results = @mysql_query($query,$cnx);
$this->pageSize = $pageSize;
if ((int)$resultpage <= 0) $resultpage = 1;
if ($resultpage > $this->getNumPages())
$resultpage = $this->getNumPages();
$this->setPageNum($resultpage);
}

function getNumPages()
{
if (!$this->results) return FALSE;

return ceil(mysql_num_rows($this->results) /
(float)$this->pageSize);
}

function setPageNum($pageNum)
{
if ($pageNum > $this->getNumPages() or
$pageNum <= 0) return FALSE;

$this->page = $pageNum;
$this->row = 0;
mysql_data_seek($this->results,($pageNum-1) * $this->pageSize);
}

function getPageNum()
{
return $this->page;
}

function isLastPage()
{
return ($this->page >= $this->getNumPages());
}

function isFirstPage()
{
return ($this->page <= 1);
}

function fetchArray()
{
if (!$this->results) return FALSE;
if ($this->row >= $this->pageSize) return FALSE;
$this->row++;
return mysql_fetch_array($this->results);
}

function getPageNav($queryvars = '')
{
if (!$this->isFirstPage())
{
$nav .= &quot;<a href=\&quot;?resultpage=&quot;.
($this->getPageNum()-1).'&'.$queryvars.'&quot;>Prev</a> ';
}
if ($this->getNumPages() > 1)
for ($i=1; $i<=$this->getNumPages(); $i++)
{
if ($i==$this->page)
$nav .= &quot;$i &quot;;
else
$nav .= &quot;<a href=\&quot;?resultpage={$i}&&quot;.
$queryvars.&quot;\&quot;>{$i}</a> &quot;;
}
if (!$this->isLastPage())
{
$nav .= &quot;<a href=\&quot;?resultpage=&quot;.
($this->getPageNum()+1).'&'.$queryvars.'&quot;>Next</a> ';
}

return $nav;
}
}

?>

DATA.PHP
*************************************
<?php
session_start();
?>
<html>

<head>
<link rel=&quot;STYLESHEET&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;>
<title> You have entered a restricted zone!</title>
</head>

<body>

<?php


print &quot;<img align=\&quot;left\&quot; src=\&quot;$_SESSION[picture]\&quot;> you are permitted to change the details and this is your user id $_SESSION[user]&quot;

?>
<a href=&quot;change.php&quot;>click to change</a>
</body>
</html>

Reality is built on a foundation of dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top