...

View Full Version : Moving pointer



mwm
06-20-2006, 05:43 PM
Can anyone show me how move the resultset pointer to the next and previous record.

Thanks

rlemon
06-20-2006, 05:59 PM
hrmm, well if your stepping through the results from a sql query

<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
print "ID: ".$row[0]." = > Name: ".$row['name']."\n";
}

mysql_free_result($result);
?>

and if your using the PEAR DB object

while($row = $results->fetchRow())
{
print "ID: ".$row[0]." = > Name: ".$row['name']."\n";
}

mwm
06-20-2006, 06:50 PM
This is what I have. I pulls a list of invoice from a db and has a link for each so when it clicked it displays the invoice image. What I can seem to do is once one image is displayed I need to call the next and previous next. Any Idea's . My code is sloppy I'm new to this


********************first page
<html>

<body>
<head><link rel=stylesheet type=text/css href=css/default.css></head>
<h1>

<form name = "result" form action = "final.php" method ="POST">
<?

include ("conn1.php");

session_start();
//session_register("ven","imageid");
$invoicetotal = $_POST['invoicetotal'];
$result = $_POST['result'];
$idnum = $_POST['idnum'];
$ven= $_POST['ven'];
$imageid = $_POST['imageid'];

//$array[] = $row['idnum'];

$sql = "
SELECT idnum, ven,veninvoice,kirkcheck,community,imageid
FROM corp
WHERE ven LIKE '%$ven%'
AND veninvoice LIKE '%$veninvoice%'
AND kirkcheck LIKE '%$kirkcheck%'
AND community LIKE '%$community%'
AND idnum LIKE '%$idnum%'
AND imageid LIKE '%$imageid%' order by 'idnum'
";



$result= mysql_query($sql) or die ("Can't connect");
for ($i = 0; $i <count($array); ++$i) {
echo "<pre>". print_r($array);

//print $array[$i];
}

$invoicetotal = mysql_num_rows($result);

echo "Total Invoices $invoicetotal";

?>

<table border="0">

<th>Vendor</th>
<th>Invoice</th>
<th>Check</th>
<th>Community</th>
<?php
//$array[] = $row['idnum'];
//echo "<pre>". print_r($array);
//$idnum = array();
$j = 0;



//while ($row = mysql_fetch_assoc($result)) {

while ($row = mysql_fetch_array($result)) {

//$array[] = $row['idnum'];
//echo "<pre>". print_r($array);
//mysql_data_seek($result);

echo ($j++%2==0) ? '<tr bgcolor="#FFFFCC">' : '<tr bgcolor="#FFFFFF">';
echo "<td>" .($row['ven']) . "</td>";
echo "<td>" .($row['veninvoice']) . "</td>";
echo "<td>" .($row['kirkcheck']) . "</td>";
echo "<td>" .($row['community']) . "</td>";

print '
<td>


<a href="final.php?idnum='.$row['idnum'].'">view</a>
</td>
';

}
echo '</table>';


?>
</form>
</html>


*******************second page***********
<html>
<style type="text/css">
body { color: black; background: #ffffaa; }
</style>
<form name = "final" form action = "final.php" method ="POST">

<?






include ("conn1.php");
session_start();
//echo "$invoicetotal";
//echo "$result";
//$array[] = $_POST['idnum'];


//$array[] = array($idnum);
//$idnum = array($idnum);
//echo "<pre>". print_r($array);
//print_r($_POST);
//print_r($idnum);

$query = "SELECT * FROM corp WHERE idnum='$idnum'";
$result1 = mysql_query($query);
$row = mysql_fetch_row($result1);
$imageid = $row[5];

echo "<img src=$imageid.gif border = 4 align = right width=\"88%\">";
/*
$nextid = next($idnum);
echo "<a href =\"final.php?idnum=$nextid\">Next</a><BR>";
echo "<a href=\"final.php?idnum=$previd\">Previous</a><BR>";
echo "<a href =\"corpfind.php\">New Search</a><BR>";


$query2 = "SELECT * FROM corp WHERE idnum='$idnum'";
$result2 = mysql_query($query2);
$row = mysql_fetch_row($result2);


$string = isset($_POST["array"]);
$array = unserialize($string);

echo "<pre>". print_r($array);

$mode = next($idnum);
//$nextid = $array + 1;
echo "<a href =\"final.php?idnum=$mode\">Next</a><BR>";
//array = array();
//echo $result;
//echo $idnum;
//print_r($idnum);
print_r($_POST);
print_r($idnum);



if(is_array($_POST["idnum"])) {


$idnum = implode(",",$_POST["idnum"]);
}


$query = "SELECT * FROM corp WHERE idnum='$idnum'";
$result1 = mysql_query($query);
$row = mysql_fetch_row($result1);
$imageid = $row[5];

echo "<img src=$imageid.gif border = 4 align = right width=\"88%\">";




$previd = $idnum -1;
$nextid = $idnum +1;

echo "<a href =\"final.php?idnum=$nextid\">Next</a><BR>";
echo "<a href=\"final.php?idnum=$previd\">Previous</a><BR>";
echo "<a href =\"corpfind.php\">New Search</a><BR>";



*/
?>


</body>
</html>

rlemon
06-20-2006, 08:55 PM
that code is messed up... like i'm not even going to attempt to follow it.

Try better to explain what you need.


Here is what i think:
you have

page.php?id=123

and you want on said page to have the following links.

<a href="page.php?id=122">prev</a>
<a href="page.php?id=124">next</a>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum