Thanks bpat - that cleared up my error but it only returns a value of -1, which I am guessing could refer to a boolean of false??? Wouldn't false return 0?
Here is a different search script I am having the same problem with. Very similar script but it limits the results to 10 per page and carrys the rest. I went ahead and made the same change here, and it also errors on db2_num_rows but completes the script??
Could this be a DB2 database issue, when using the db2_num_rows? I can get it to work on a MySQL database;
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
$uppercase = strtoupper($trimmed);
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($uppercase == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
$i5db2 = db2_connect("bla",
"blauser",
"blapass",
array("i5_lib"=>"files"))
or die("Connect error: " . db2_conn_errormsg());
// SQL Query
$query = "SELECT *
FROM O.ITEMPICT
WHERE ucase(PKEYWD) like '%$uppercase%' or ucase(PITEM) like '%$uppercase%' or ucase(PSDESC) like '%$uppercase$' or ucase(PGENDR) like '%$uppercase%' ";
$run=db2_prepare($i5db2, $query);
$numresults=db2_exec($i5db2, $query);
$numrows=db2_num_rows($run);
// If we have no results, offer a google search as an alternative
if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: "" . $uppercase . "" returned zero results</p>";
// google
echo "<p><a href=\"http://www.google.com/search?q="
. $uppercase . "\" target=\"_blank\" title=\"Look up
" . $uppercase . " on Google\">Click here</a> to try the
search on google</p>";
}
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// *****************************PROBLEM AREA*******************
// *****************************PROBLEM AREA*******************
//$query .= " limit $s,$limit";
//$result = db2_exec($i5db2, $query) or die("Couldn't execute query");
// *****************************PROBLEM AREA*******************
// *****************************PROBLEM AREA*******************
// display what the person searched for
echo "<p>You searched for: "" . $uppercase . ""</p>";
// begin to show results set
echo "<h3><font face=\"Arial, Helvetica, sans-serif\" color=\"red\">Here Are Your Results:</font></h3>";
$count = 1 + $s ;
// now you can display the results returned
while ($row = db2_fetch_assoc($numresults)) {
$title = $row['PITEM'];
if (@file_exists('catalog/'.rtrim($row['PITEM']).'.jpg')) {
echo '<img src=\'catalog/'. rtrim($row['PITEM']).'.jpg\' border=1 />';
echo '<br />';
}
else{
echo ' ';
}
echo '<h3><font face=\"Arial, Helvetica, sans-serif\">';
echo "$count.) $title" ;
$count++ ;
echo '<br />';
echo '</font></h3>';
//echo '<p><h3><strong>'.($count++).'. Product Number: ';
//echo htmlspecialchars(stripslashes($row['PITEM']));
echo '<br /><strong><font face=\"Arial, Helvetica, sans-serif\">Description:</strong><br /> ';
echo ucfirst($row['PSDESC']);
echo '<br /><br /><strong>Size: </strong>';
echo stripslashes($row['PSIZE']);
echo '<br /><strong>Color: </strong>';
echo ucfirst($row['PCOLOR']);
echo '<br /><strong>Gender: </strong>';
echo ucfirst($row['PGENDR']);
echo '<br /><strong>Material: </strong>';
echo ucfirst($row['PMATRL']);
echo '<br /><strong>2007 Catalog Page Number: </strong></font><font face=\"Arial, Helvetica, sans-serif\" color=\"red\">';
echo ucfirst($row['PCCPGE']);
echo "</font><hr>";
echo '</p>';
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
Prev 10</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
?>
</body>
</html>
Also, w/ the above I am having an issue w/ the "problem area" - when those aren't commented out - it also errors on the db2_num_rows?
Here is the error message.
Warning: db2_num_rows() [function.db2-num-rows]: SQLRowCount failed in /www/zendcore/htdocs/TEST/search.php on line 44
Results
Sorry, your search: "BASEBALL" returned zero results
Click here to try the search on google
Warning: db2_execute() expects parameter 2 to be array, string given in /www/zendcore/htdocs/TEST/search.php on line 70
Execute error:
From what I read in regards to the db2_num_rows function, it appears when I run a SELECT statement, I need to declare a scrolling cursor b/c the with the DB2 the db2_num_rows will only return a boolean value.
If that is the case would I declare that in my SELECT statement or does that need to be declared before hand? Actually I am not too familar with cursors, so I am not sure where to start - maybe:
$sqlStatment = "DECLARE name SENSITIVE SCROLL CURSOR FOR SELECT * FROM O.ITEMPICT
WHERE $searchstring";
Sorry if the is vague.
Thanks for your help!!
John