Hello. My client has a "list all inventory" link. The linked page contains the inventory list, which can contain up to 100 or more items. Unfortunately, they are only supplying me with a comma delimited csv file for their database. So I've linked to the database with ODBC. The code that follows works, except that every page in the pagination returns the same 10 items (the first 10). I cannot get beyond this.
<?php
include('../common/header.php');
include('../common/nav.php');
include('../scripts/ubiquitous.php');
?>
<div id="container">
<div class="main2">
<?php
$page = isset($_GET["allinv2"]) ? $_GET["allinv2"] : 1;
if(empty($page)){$page = 1; }
$query = "SELECT * FROM company.csv";
$num_result = odbc_exec($db, $query);
$numrows = inv_rows($num_result);
echo '<p>There are currently '.$numrows.' autos in our inventory.</p>';
$limit = 10;
$limitvalue = $page * $limit - ($limit);
$limitnew = $limitvalue + $limit;
$sql = "SELECT * from (SELECT TOP 10 * from (SELECT TOP $numrows * from company.csv order by make, model, year, sellingprice asc) as table1 order by make, model, year, sellingprice asc) as table2 order by make, model, year, sellingprice asc";
$result = odbc_exec($db, $sql);
while(odbc_fetch_row($result)){
?>
<form action="moreinfo.php" method="post">
<table style="width: 100%; margin: auto;">
<tr>
<td style="width: 20%" rowspan="4"><img alt="Photo" src="<?php echo odbc_result($result, "photourl1"); ?>" width="100" height="75" /></td>
<td style="width: 20%; height: 25px;">Make</td>
<td style="width: 20%; height: 25px;"><?php echo odbc_result($result, "make"); ?></td>
<td style="width: 20%; height: 25px;">Model:</td>
<td style="width: 20%; height: 25px;"><?php echo odbc_result($result, "model"); ?></td>
</tr>
<tr>
<td style="width: 20%; height: 25px;">Year:</td>
<td style="width: 20%; height: 25px;"><?php echo odbc_result($result, "year"); ?></td>
<td style="width: 20%; height: 25px;">Transmission:</td>
<td style="width: 20%; height: 25px;"><?php echo odbc_result($result, "transmission"); ?></td>
</tr>
<tr>
<td style="width: 20%; height: 25px;">Miles</td>
<td style="width: 20%; height: 25px;"><?php echo odbc_result($result, "miles"); ?></td>
<td style="width: 20%; height: 25px;">Price:</td>
<td style="width: 20%; color:#cdeb8b; height: 25px;"><strong>$<?php echo odbc_result($result, "sellingprice"); ?>.00</strong></td>
</tr>
<tr>
<td style="width: 20%; height: 25px;"><input name="Submit1" type="submit" value="More Info" /></td>
<td style="width: 20%; height: 25px;"> </td>
<td style="width: 20%; height: 25px;"> </td>
<td style="width: 20%; height: 25px;"> </td>
</tr>
<tr>
<td colspan="5" style="height: 25px"><hr/></td>
</tr>
</table>
<input type="hidden" name="moreinfo" value="<?php echo odbc_result($result, "vin"); ?>"/>
</form>
<?php
}
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);
?>
</div>
<?php
include('../common/sidebar.php');
include('../common/footer.php');
exit;
?>
FYI:
inv_rows is a function I put together in ubiquitous.php which simply counts the total records. Here is the code for ubiquitous.php:
<?php
$make = $_POST['make'];
$model = $_POST['model'];
$moreinfo = $_POST['moreinfo'];
$hidollar = $_POST['hidollar'];
$lodollar = $_POST['lodollar'];
$db = odbc_connect("Company","","");
function inv_rows($r1) {
ob_start();
(int)$number=odbc_result_all($r1);
ob_clean();
return $number;
}
?>
I think my problem is in my sql statement, but I'm not really sure. This is a piece of cake for me in MySQL, but my first time around with an ODBC connection. The syntax is different, and to my surprise, there's very little info on the web about proper PHP/ODBC etiquette. Thanks in advance for your help. If you need additional info, don't hesitate to ask.
You can view the actual page here.