Big.nerd: I am not sure what you are saying on that last post. I can hard code a name from the database in the WHERE clause and display an entry of that hard coded name. Of course the hard coding name is for testing only. What is the proper syntax to display all the names if I use the WHERE clause? Or, do I use the WHERE clause?
Information about my code:
Table name = plastic
Primary key = plastic_ID
column name = ename
column name = iname
This page should display how many names (as a number) are in the database, list the first 5 names and the iname information along with the PREV and NEXT buttons.
My code with your corrections tells how many names are in the database but does not display any names. The PREV and NEXT buttons don't do anything. I am still not sure if line nine has the proper wording of "page". I appreciate your help with this. Thank you.
<?php
$db = odbc_connect('WEB_PROD_IDEAS','write','write123'); //put your connection here
function inv_rows($r1) {
ob_start();
(int)$number=odbc_result_all($r1);
ob_clean();
return $number;
}
$page = isset($_POST["page"]) ? $_POST["page"] : 1; //not sure of "page" text
if(empty($page)){$page = 1; }
$query = "SELECT * FROM plastic"; //name of table is plastic with columns plastic_ID, ename, and iname.
$num_result = odbc_exec($db, $query);
$numrows = inv_rows($num_result);
echo '<p>There are '.$numrows.' ideas.</p>';
$limit = 5;
$limitvalue = $page * $limit - ($limit);
$limitnew = $limitvalue + $limit;
$max = 5; // Number Results/Page
$start = 6; // This would be the where you start, i.e. 16, 31 (1 after last result item)
$sql = "SELECT TOP $max * FROM plastic WHERE ename = 'yes' AND (plastic_ID NOT IN (SELECT TOP $start plastic_ID FROM plastic ORDER BY plastic_ID)) ";
$result = odbc_exec($db, $sql);
while(odbc_fetch_row($result)){
?>
<table style="width: 600;">
<tr>
<td style="width: 300; height: 25px;">Name:</td>
<td style="width: 300; height: 25px;">Idea Name:</td>
</tr>
<tr>
<td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td>
<td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td>
</tr>
<tr>
<td colspan="5" style="height: 25px"><hr/></td>
</tr>
</table>
<?php //PREVIOUS AND NEXT BUTTONS
}
if($page !=1){
$pageprev = $page - 1;
echo ' <strong><a href="?page='.$pageprev.'">PREV</a></strong> '; }
else{ echo " PREV "; }
$numofpages = $numrows / $limit;
for($i = 1; $i <= $numofpages; ++$i){
if($i == $page){ echo " [$i] "; }
else{ echo " <strong><a href='?page=$i'>$i</a></strong> "; }
}
if(($numrows % $limit) != 0){
if($i == $page){ echo " [$i] "; }
else{ echo " <strong><a href='?page=$i'>$i</strong></b> "; }
}
if(($numrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
echo " <strong><a href='?page=$pagenext'>NEXT</a></strong> "; }
else{ echo " NEXT "; }
odbc_free_result($result);
exit;
?>