/    Sign up×
Community /Pin to ProfileBookmark

Weird MySQL error??

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

[/QUOTE]

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>&nbsp;<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″>&#171;
</a>’;
$prev = ‘<a href=”‘.$_SERVER[‘PHP_SELF’].$query_str.($pg – 1).'”>
&#139;</a>’;
$next = ‘<a href=”‘.$_SERVER[‘PHP_SELF’].$query_str.($pg + 1).'”>
&#155;</a>’;
$last = ‘<a href=”‘.$_SERVER[‘PHP_SELF’].$query_str.$pages.'”>
&#187;</a>’;

echo ‘<div><center><br><br>’;
echo ($pg > 1) ? “$first : $prev :” : ‘&#171; : &#139; :’;

$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” : ‘: &#155; : &#187;’;
echo ‘</center></div>’;

// Close connection
mysql_close($conn);
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@DeekerauthorMar 22.2007 — Okay, I fixed the weird MySQL error... For some reason I put a limit on one of my count queries which was messing it up.... But I'm still not able to get the category variable to carry over from page to page....

any ideas or suggestions would be outstanding.

Thanks
×

Success!

Help @Deeker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...