Jump to content

Pagination with columns! (I have been trying this for hours!)


Recommended Posts

Hi all, I have been at this for hours and its really making me mad!! I would like a pagination that displays in columns as well as rows (I have searched everywhere and everyones script seems to fail on me :(..

 

I would like to take results from the database that is linked with the userid..

 

EG.

 

music1    music2    music3

music4    music5    music6

music7    music8    music9

 

First Previous 1 2 3 4 5 6 7 8 9 10 Next Last

 

Here is the code I'm using.. it displays the results correctly but when I click "next" it says no data? (I found a pagination script AND I found a script that lets me display data in columns.. I tried to merge them together and I failed :(

 

Here is MY merge attempt:

<script language="JavaScript" src="js/pagination.js"></script>
<link rel="stylesheet" type="text/css" href="css/station.css" />
<?php

include("connectvars.php");
include('pagination_class.php');

if($_GET['id'])
{

$tdcount = 1;  
$numtd = 3; // number of cells per row
print "<table width=\"100%\" valign=\"top\" align=\"center\">"; 
$id = mysql_real_escape_string($_GET['id']);		
$dd = mysql_query("SELECT * FROM `accounts` WHERE `user_id`='".$id."'") or die(mysql_error());
$ee = mysql_query("SELECT * FROM `music` WHERE `musicuploaderid`='".$id."'") or die(mysql_error());


$qry = "SELECT * FROM `music` WHERE `musicuploaderid`='".$id."'";
$searchText = "";
if($_REQUEST['search_text']!=""){
	$searchText = $_REQUEST['search_text'];
	$qry .=" where channel_name OR display_name like '%$searchText%'";
}

//for pagination
$starting=0;
$recpage = 9;//number of records per page

$obj = new pagination_class($qry,$starting,$recpage);		
$result = $obj->result;
?>

<form name="form1" action="pagnation1.php" method="POST">

<table border="0" align="center" width="100%">
<tr>
<TD colspan="2" align="right" valign="middle" height="0">
<div id="content">Search <input type="text" name="search_text" class="input3" value="<?php echo $searchText; ?>">
<input type="submit" value="Search"></div></TD> 
</tr>
<tr><TD colspan="2">

<div id="page_contents">

<?php

print "<table width=\"100%\" valign=\"top\" align=\"center\">"; 

if(mysql_num_rows($result)!=0)
{
	$counter = $starting + 1;
	while($s = mysql_fetch_array($result))
	{


	if ($tdcount == 1) print "<tr>";

	print "
	<td width=\"275\" valign=\"top\" align=\"center\"><a target=\"_top\" href=\"media.php?v=".$s['musicid']."\">";

	echo "<img src=\"$s[musicalbumart]\" width=\"90\" height=\"90\" border=\"0\" align=\"center\"><br>

	<div id=\"content\" align=\"center\">".$s['musictitle']."<br>".$s['musicartist']."</a><br>".$s['musicrating']."</div><br></td>"; 

	if ($tdcount == $numtd) 
	{  
		print "</tr>";  
		$tdcount = 1;
		$counter ++;
	}
	else
	{  
		$tdcount++;  
	}  
} 

if ($tdcount!= 1)
{  
	while ($tdcount <= $numtd)
	{  
		print "<td> </td>";  
		$tdcount++;  
	}  
	print "</tr>";
	$counter ++;
}
else
{ 
	echo "";
}  

print "</table>";
	?><tr><TD colspan="7"><? echo $obj->anchors; ?></TD></tr>
	<tr><TD colspan="7" align="center"><? echo $obj->total; ?></TD></tr><?php


}else{
				echo '<tr><TD align="center" colspan="2"><div id="content">No Data Found</div></TD></tr>';
}


} ?>

</TD></tr>
			</table>
		</div>
		</TD></tr>
	</table></form>

 

Original Pagination script:

 

<?php

include('pagination_class.php');
mysql_connect('localhost', '      ', '     ') or die(mysql_error());
mysql_select_db(' ');
?>
<script language="JavaScript" src="js/pagination.js"></script>
<link rel="stylesheet" type="text/css" href="css/station.css" />
<?
$qry = "SELECT * FROM accounts";

if($_REQUEST['search_text']!=""){
$searchText = $_REQUEST['search_text'];
$qry .=" where channel_name OR display_name like '%$searchText%'";
}

//for pagination
if(isset($_GET['starting'])&& !isset($_REQUEST['submit'])){
$starting=$_GET['starting'];
}else{
$starting=0;
}
$recpage = 10;//number of records per page

$obj = new pagination_class($qry,$starting,$recpage);		
$result = $obj->result;
?>
							<table border="0" align="center" width="100%">

			<?if(mysql_num_rows($result)!=0){
			$counter = $starting + 1;
			while($data = mysql_fetch_array($result)) 
			{


				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1);
				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1);
				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1);
				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1); ?>
<tr>
	<td height="0" width="592">					
	<table border="1" width="100%" height="0" cellspacing="0" cellpadding="0" bordercolor="#c0c0c0" bgcolor="#FFFFFF" class="mytable"><tr height="10" class="special">
				<TD width="64" height="79" rowspan="2" align="center"><div id="content"><? echo $counter; ?></div></TD>
				<TD height="0" width="633" colspan="3">
				<div align="left" id="content">
				<?php echo "".$data['channel_name'].""; ?> (<?php echo "".$data['display_name'].""; ?>)</div></TD>
				<TD height="0" width="184">
				<div id="content" align="right">+Add to favourites</TD>
				</tr>

				<tr class="special">
				<TD height="59" width="107">
				<p align="center">
				<img src=<?php echo "".$data['display_picture'].""; ?> width=49 height=51 border=0 align="center"></TD>
				<TD height="59" width="300" valign="top"><div id="content">
					<br>
				Views:
				<?php echo "".$data['channel_views'].""; ?><br>
				Rating:
				<?php echo "".$data['channel_rating'].""; ?></div></TD>
				<TD height="59" width="222" valign="top"><div id="content"><br>Music: <?php echo "".$n1.""; ?><br>
				Pictures: 0</TD>
				<TD height="59" width="184" valign="top"><div id="content"><br>Files: 0<br>
				Lyrics: 0</div></TD>
				</tr></table>


				</td>
</tr><tr><td height="2"></td></tr>
<? $counter ++;

			} ?>

			<tr><TD colspan="7"><? echo $obj->anchors; ?></TD></tr>
			<tr><TD colspan="7" align="center"><? echo $obj->total; ?></TD></tr>
			<?}else{?>
				<tr><TD align="center" colspan="2"><div id="content">No Data Found</div></TD></tr>
			<?}?>
			</TD></tr>
			</table>



 

Original Script For Columns:

<link rel="stylesheet" href="css/MMUV1.css" type="text/css" media="screen" />
<?php

include("connectvars.php");

if($_GET['id'])
{

$tdcount = 1;  
$numtd = 3; // number of cells per row  
print "<table width=\"100%\" valign=\"top\" align=\"center\">"; 
$id = mysql_real_escape_string($_GET['id']);		
$dd = mysql_query("SELECT * FROM `accounts` WHERE `user_id`='".$id."'") or die(mysql_error());
$ee = mysql_query("SELECT * FROM `music` WHERE `musicuploaderid`='".$id."'") or die(mysql_error());

echo "If you can see this page its VERY unfinished <br><br>";

while($s = mysql_fetch_array($ee))
{

	if ($tdcount == 1) print "<tr>";

	print "
	<td width=\"275\" valign=\"top\" align=\"center\"><a target=\"_top\" href=\"media.php?v=".$s['musicid']."\">";

	echo "<img src=\"$s[musicalbumart]\" width=\"90\" height=\"90\" border=\"0\" align=\"center\"><br>

	<div id=\"content\" align=\"center\">".$s['musictitle']."<br>".$s['musicartist']."</a><br>".$s['musicrating']."</div><br></td>"; 

	if ($tdcount == $numtd) 
	{  
		print "</tr>";  
		$tdcount = 1;  
	}
	else
	{  
		$tdcount++;  
	}  
} 
if ($tdcount!= 1)
{  
	while ($tdcount <= $numtd)
	{  
		print "<td> </td>";  
		$tdcount++;  
	}  
	print "</tr>";  
}
else
{ 
	echo "";
}  
print "</table>"; 


} ?>

 

Please help I have been at it for hours and I'll tear my hair out if I can't solve it! :confused:

 

get your pagination script working first without the columns.  Then for the columns do this

$counter=1;
echo "<table>"; 
echo "<tr>";
foreach($resultset as $result)
{
echo "<td>".$displayedresults."</td>"; 
if($counter%3==0) { 
      echo "</tr><tr>"; 
}
$counter++; 
}
echo "</tr>"; 
echo "</table>"; 

Thanks for the quick reply :), I did my pagination without the columns and it worked, I replace the code with yours and I get a error

 

http://www.mymediaupload.com/stations_mem.php

<?php
error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');
mysql_connect('localhost', 'root', 'msb090909') or die(mysql_error());
mysql_select_db('mymediaupload');
?>
<script language="JavaScript" src="js/pagination1.js"></script>
<link rel="stylesheet" type="text/css" href="css/station.css" />
<?
$qry = "SELECT * FROM music";
$searchText = "";
if($_REQUEST['search_text']!=""){
$searchText = $_REQUEST['search_text'];
$qry .=" where channel_name OR display_name like '%$searchText%'";
}

//for pagination
$starting=0;
$recpage = 5;//number of records per page

$obj = new pagination_class($qry,$starting,$recpage);		
$result = $obj->result;


		?><form name="form1" action="stations_mem.php" method="POST">

		<table border="0" align="center" width="100%">
		<tr>
		  <TD colspan="2" align="right" valign="middle" height="0">
			<div id="content">Search <input type="text" name="search_text" class="input3" value="<?php echo $searchText; ?>">
				<input type="submit" value="Search"></div>
		  </TD> 
		</tr>
		<tr><TD colspan="2">

		<div id="page_contents">

			<table border="0" align="center" width="100%">

			<?if(mysql_num_rows($result)!=0){
			$counter = $starting + 1;
			while($data = mysql_fetch_array($result)) 
			{


				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1);
				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1);
				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1);
				$r1 = mysql_query("SELECT * FROM music WHERE `musicuploaderid`='".$data['user_id']."'");
				$n1 = mysql_num_rows($r1); ?>
<tr>
	<td height="0" width="592">					
				<?php

				$counter=1;
				echo "<table>"; 
				echo "<tr>";
				foreach($resultset as $result)
				{
					echo "<td>".$displayedresults."</td>"; 
					if($counter%3==0)
					{ 
      							echo "</tr><tr>"; 
					}
					$counter++; 
				}
				echo "</tr>"; 
				echo "</table>"; 
				?>


				</td>
</tr><tr><td height="2"></td></tr>
<? $counter ++;

			} ?>

			<tr><TD colspan="7"><? echo $obj->anchors; ?></TD></tr>
			<tr><TD colspan="7" align="center"><? echo $obj->total; ?></TD></tr>
			<?}else{?>
				<tr><TD align="center" colspan="2"><div id="content">No Data Found</div></TD></tr>
			<?}?>
			</TD></tr>
			</table>
		</div>
		</TD></tr>
	</table></form>

Warning: Invalid argument supplied for foreach() in C:\inetpub\vhosts\mymediaupload.com\httpdocs\stations_mem.php on line 61

 

Can you please verify that I did it correctly?

 

 

that was just an example you have to replace the values with your own.

while($s = mysql_fetch_array($result))
{

would replace this

foreach($resultset as $result)
{

you would define $counter before that.

the variables don't exist in your script.

 

then this

      print "
      <td width=\"275\" valign=\"top\" align=\"center\"><a target=\"_top\" href=\"media.php?v=".$s['musicid']."\">";

      echo "<img src=\"$s[musicalbumart]\" width=\"90\" height=\"90\" border=\"0\" align=\"center\"><br>

      <div id=\"content\" align=\"center\">".$s['musictitle']."<br>".$s['musicartist']."</a><br>".$s['musicrating']."</div><br></td>"; 

would replace the <td>".$dataset."</td>

you have to think about it people aren't going to want to help if you don't do a little thought process of your own and at least try to figure it out first. You just copy and pasted.

No offence but I have been at this thing for hours and I'm really getting tired with it.. I have tried several ways to try to make it work and it fails all the time, I know PHP well but at this point of time I'm tired..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.