0

I'm trying really hard to figure out why information from a database won't show up. I think my query is failing, but I've talked to a few people and they don't know why it's not working.

Here's my code leading up to the query:

$getnum = mysql_query("SELECT * FROM articles ORDER BY artnum DESC LIMIT 1");

while($getnumrow = mysql_fetch_array($getnum))
{
    $theartnum=$getnumrow['artnum'];
}

$pagenum=intval($_GET['pg']);
if($pagenum==0 || !isset($pagenum))
{
    $pagenum=1; 
}
$offsetnum = $theartnum-($pagenum*15)+15;
echo("SELECT * FROM articles ORDER BY artnum DESC LIMIT 15 OFFSET $offsetnum");
$result=mysql_query("SELECT * FROM articles ORDER BY artnum DESC LIMIT 15 OFFSET $offsetnum");

I've went over the variables, and all seem to be working. Echoing the query, I get:

SELECT * FROM articles ORDER BY artnum DESC LIMIT 15 OFFSET 85

Which should work, since I've checked and the amount in articles is 85.

Much later in the code, I have:

while($row = mysql_fetch_array($result))
{
$art_title=$row['art_title'];
$art_title_url=$row['art_title_url'];
$art_author=$row['art_author'];
$art_date=$row['art_date'];
$artnumber=$row['artnum'];
$desc=implode(' ', array_slice(explode(' ', $row['article']), 0, 14))."...";
echo "<div class=\"big\"><a href=\"newsn.php?art=".$art_title_url."\">".$art_title."</a></div>
<div class=\"small\">".$art_date." — <a title=\"View more by ".$art_author."\" href=\"author.php?a=".$art_author."\">".$art_author."</a></div>
<span class=\"article\">".$desc."</span><br /><br />";
}

If I put

echo "test";

in there, I don't get that either.

My whole code is here:

http://pastebin.com/RUpb0tUG

(note: It's not complete, I'm still working on the previous/next buttons and I can do that fairly easily)

I'm testing it here until it works.

Thanks!

2 Answers 2

5

SELECT * FROM articles ORDER BY artnum DESC LIMIT 15 OFFSET 85

Which should work, since I've checked and the amount in articles is 85.

Aha, if you have 85 records in your table, what do you expect to get from the above select from row number 86 to 100 other than an empty result set ??

Sign up to request clarification or add additional context in comments.

1 Comment

Ohhh. Thanks so much, I didn't realize that it was pulling from articles ABOVE 85. Thank you!
0

Any chance the problem lies in your "header.php" include file containing code that uses the $result variable or another variable that will screw up your later code?

1 Comment

Thanks, but I had previously checked and made sure that the variables used in header.php to get other information never got mixed up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.