Hello Everyone,
I’m getting a MySQL error that I’ve never seen before. I have a script that is pulling various information from a large table in my database. Because it’s such a large table, I’ve broken it up into smaller pages using the basic paginate technique.
I’ve gotten the code to work fine and pull what it is I need from the table but, like I said, its a large table. I’m trying to create a way for the user to select a category from a basic select form. I’ve gotten it to where when the user selects a category, it brings up those items in that category for the user to browse BUT when the user goes to another page I’m getting this weird MySQL error that I don’t know how to handle. This is what the error says:
[QUOTE]
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5
Here’s my code so far:
[code=php]
// Get page information
$display = 20;
$pg = (isset($_REQUEST[‘pg’]) && ctype_digit($_REQUEST[‘pg’])) ?
$_REQUEST[‘pg’] : 1;
$start = $display * $pg – $display;
// Get connection information and connect
$conn = mysql_connect(“localhost”, “name”, “password”);
mysql_select_db(“myDB”, $conn);
$query = mysql_query(“SELECT DISTINCT `category` FROM `MyTable`”);
?>
<center>
<form method=’post’
name=’categoryForm’
action=<?php echo $_SERVER[‘PHP_SELF’] . “>”; // Start Form
// Establish if $category is empty or not
$category = !isset($_POST[‘category’])? NULL : $_POST[‘category’];
// Start filling the Select Menu
echo “<select name=’category’>
<option value=’all’>View All</option>”;
// WHILE loop to fill the select menu
while ($rowCategory = mysql_fetch_array($query)){
echo “<option value='” . $rowCategory[‘category’] . “‘>” . $rowCategory[‘category’] . “</option>”;
} // end While
// Finish select menu and form
echo “</select> <input type=’submit’ name=’submit’ value=’Go’>
</form></center><br><br><br>”;
// Determine How Many pages there will be in relation to category selected
if ($category == “all” || !empty($_POST[‘category’])){
$result = mysql_query(“SELECT count(*) FROM MyTable”);
}else{
$result = mysql_query(“SELECT count(*) FROM MyTable WHERE `category` = “$category” “);
} // end IF
// Determine what the user wants to see
$total = mysql_result($result, 0);
if ($category == “all” || !empty($_POST[‘category’])){
$product = mysql_query(“SELECT * FROM myTable LIMIT $start, $display”);
}else{
$product = mysql_query(“SELECT * FROM myTable WHERE `category` = “$category” LIMIT $start, $display”);
} // end IF ELSE
//
// Content Built From myTable
//
// Start paginate stuff
if (isset($_SERVER[‘QUERY_STRING’]) && trim($_SERVER[‘QUERY_STRING’])
!= ”) {
if(stristr($_SERVER[‘QUERY_STRING’], ‘pg=’))
$query_str = ‘?’.preg_replace(‘/pg=d+/’, ‘pg=’,
$_SERVER[‘QUERY_STRING’]);
else
$query_str = ‘?’.$_SERVER[‘QUERY_STRING’].’&pg=’;
} else
$query_str = ‘?pg=’;
$pages = ($total <= $display) ? 1 : ceil($total / $display);
$first = ‘<a href=”‘.$_SERVER[‘PHP_SELF’].$query_str.’1″>«
</a>’;
$prev = ‘<a href=”‘.$_SERVER[‘PHP_SELF’].$query_str.($pg – 1).'”>
‹</a>’;
$next = ‘<a href=”‘.$_SERVER[‘PHP_SELF’].$query_str.($pg + 1).'”>
›</a>’;
$last = ‘<a href=”‘.$_SERVER[‘PHP_SELF’].$query_str.$pages.'”>
»</a>’;
echo ‘<div><center><br><br>’;
echo ($pg > 1) ? “$first : $prev :” : ‘« : ‹ :’;
$begin = $pg – 4;
while($begin < 1)
$begin++;
$end = $pg + 4;
while($end > $pages)
$end–;
for($i=$begin; $i<=$end; $i++)
echo ($i == $pg) ? ‘ [‘.$i.’] ‘ : ‘ <a href=”‘.
$_SERVER[‘PHP_SELF’].$query_str.$i.'”>’.$i.'</a> ‘;
echo ($pg < $pages) ? “: $next : $last” : ‘: › : »’;
echo ‘</center></div>’;
// Close connection
mysql_close($conn);