0

I have built a site completely off of tutorials. aonentertainment.com in the pursuit of learning and profit to pay for classes. I want to add (Next,1,2,3,Previous) so I do not have to manually create new pages.

I searched DaniWeb.com and found >> Clean Previous Next Script for MySQL. Link to it.
http://www.daniweb.com/web-development/php/threads/1720

I keep getting this error.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\inetpub\vhosts\aonentertainment.com\httpdocs\paging1.inc.php on line 25
Pages:(1) [1]

Link to where I get the error.
http://aonentertainment.com/index.php?content=inthemix-main

What am I doing wrong?

Table = inthemix
Table items =
inthemixid
title
details
vidcode
shortdesc
thumb
brief

<?php
$server = "private";
$user = "private";
$pass = "private";
$databasename = "databasetest1";
$db = mysql_connect($server, $user, $pass);
	mysql_select_db($databasename,$db);

		$sql = "SELECT * from inthemix WHERE inthemixid = $inthemixid ORDER by inthemixid desc 
		limit 0,2";
		$query = mysql_query($sql,$db);
		$total_results = mysql_num_rows($query);
		$limit = "4"; //limit of archived results per page.
		$total_pages = ceil($total_results / $limit); //total number of pages
if (empty($page))
	{
		$page = "1"; //default page if none is selected
	}
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB

	$query = "SELECT * FROM inthemix WHERE inthemixid = $inthemixid ORDER BY desc LIMIT $offset, $limit";
	$result = mysql_query($query);
//This is the start of the normal results...

	while($row=mysql_fetch_array($result, MYSQL_ASSOC))
   {
       $inthemixid = $row['inthemixid'];
	   $thumb= $row['thumb'];
       $title = $row['title'];
       $brief = $row['brief'];
       $shortdesc = $row['shortdesc'];
	   echo "<a href=\"index.php?content=inthemix-show-all&id=$inthemixid\"><img src='$thumb' width='127' height='80' border='0' align='left' hspace='9' title='$title' alt='$title' /></a>"; 
       echo"<a href=\"index.php?content=inthemix-show-all&id=$inthemixid\"><b><center>$title</center></B></a><br>\n";
	   echo"$brief\n";
       echo"$shortdesc<br><br>\n";
	   echo"<hr></hr>";
	   
   }
		mysql_close();


// This is the Previous/Next Navigation
echo "<font face=Verdana size=1>";
echo "Pages:($total_pages)&nbsp;&nbsp;"; // total pages
if ($page != 1)
{
echo "<a href=$PHP_SELF?page=1><< First</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
$prevpage = $page - 1;
echo "&nbsp;<a href=$PHP_SELF?page=$prevpage><<</a>&nbsp;"; // <strong class="highlight">Previous</strong> Page Link
}
    	if ($page == $total_pages) 
			{
      			$to = $total_pages;
    		} 
		elseif ($page == $total_pages-1) 
			{
      			$to = $page+1;
    		} 
		elseif ($page == $total_pages-2) 
			{
     		 	$to = $page+2;
    		} 
		else 
			{
      			$to = $page+3;
    		}
    	if ($page == 1 || $page == 2 || $page == 3) 
			{
      			$from = 1;
    		} 
		else 
			{
      			$from = $page-3;
    		}
			
for ($i = $from; $i <= $to; $i++)

	{
	if ($i == $total_results) $to=$total_results;
	if ($i != $page)
		{
		echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>";
		}
	else
		{
		echo "<b><font face=Verdana size=2>[$i]</font></b>";
		}
	if ($i != $total_pages)
		echo "&nbsp;";
	}
if ($page != $total_pages)
{
$nextpage = $page + 1;
echo "&nbsp;<a href=$PHP_SELF?page=$nextpage>>></a>&nbsp;"; // <strong class="highlight">Next</strong> Page Link
echo "&nbsp;&nbsp;&nbsp;<a href=$PHP_SELF?page=$total_pages>Last >></a>"; // Last Page Link
}
echo "</font>";

// This is the end of the Previous/Next Navigation
?>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
9
Replies
12
Views
5 Years
Discussion Span
Last Post by Stefano Mtangoo
0

This is line 25 on my Note++
while($row=mysql_fetch_array($result, MYSQL_ASSOC))

0

I think you are missing the numerical rows..

Try this

## we need to get the count of affected rows by your query
## putting a LIMIT will obviously limit your result and may not have anything left ## for the script to paginate.
$sql = "SELECT COUNT(*) from inthemix WHERE inthemixid = $inthemixid ORDER by inthemixid desc";
$query = mysql_query($sql,$db);
## we get the result count
$total_results = mysql_num_row($query);
## the numerical rows
$num_rows = $total_results[0];
## define the  number of items on the page
$limit = "4"; //limit of archived results per page.
## calculate how many pages the script has to make
$total_pages = ceil($num_rows / $limit); //total number of pages

Try it first..the rule of thumb are like these

1. Count the rows of the items you want to paginate.
2. Once we have gotten the number of rows, divide that number by the items we want to be showing on the page.
3. Give the current page a number designation e.g. 1
4. Calculate the offset. Such as $offset = ($currentpage - 1) * $rowsperpage;
5. Send your database query to fetch the actual items in the database using the criterion of the count as LIMIT.
6. Sit back, relax, analyze, and if it doesn't work go back and do it all over again.

0

Thank you for your response. I reviewed your information.
I pluged it in.
But it says error.
Link to page with error. http://aonentertainment.com/index.php?content=inthemix-main

In my notepad++ line 11 is: $total_results = mysql_num_row($query); Here is the section in reference

$sql = "SELECT COUNT(*) from inthemix WHERE inthemixid = $inthemixid ORDER by inthemixid desc";
    $query = mysql_query($sql,$db);
    $total_results = mysql_num_row($query);
    $num_rows = $total_results[0];
    $limit = "4"; 
    $total_pages = ceil($num_rows / $limit);

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Im not sure if it matters since it would appear to the browser like it was originally their, but I have added this script as an include on this page below another include I would like to remove once this script works.

0

Im not sure if it matters since it would appear to the browser like it was originally their, but I have added this script as an include on this page below another include I would like to remove once this script works.

oh no...:), the script responsible for showing your content must be the same script counting the row and doing the pagination. Try looking at the script responsible for showing your content on your page. You can probably insert the pagination codes there. I am pretty sure it will be a lot easier than including a new one to do the pagination for the other.

0

I Received another error.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\inetpub\vhosts\aonentertainment.com\httpdocs\paging1.inc.php on line 25

Line 25. while($row=mysql_fetch_array($result, MYSQL_ASSOC))

Sory for the mix up. The whole PHP script is included on the left colume of the page as an include. the Include above it is displaying the current videos.

Thanks for the link to the pagination. Soon as I get off work and some rest. I will review and see If I cant tackle this head on.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.