PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > The PowWeb Platform > PHP
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
Old 5-4-12, 07:20 AM   #1
HWND
Registered
 
Join Date: May 2012
Location: Cardiff
Posts: 2
Reputation: 0
PHP SQL tables and pagination - help please!

Hello

First, let me point out I'm not fluent in PHP, as my coding will testify!

This code was created for me about 10 years ago when I first launched my website. I managed to cobble together a search function about 5 years ago (not quite sure how though!). The best that can be said of it is that it works, but it is the main reason people visit my website.

Here it is in action - http://hardcorewillneverdie.com/archive.php (also used for http://hardcorewillneverdie.com/mixes.php and http://hardcorewillneverdie.com/tracklist.php and http://hardcorewillneverdie.com/flyer.php )

I would like to clean it up. As you can see from the link above the pagination shows every page number and is a bit of mess, this needs to be trimmed down as per this example - maybe even with some nice boxes too!

http://www.phpeasystep.com/phptu/29.html

I would also like to either display the pagination both above and below the results, if not just shift it below.

I would also like to allow the user the option to select the number of results displayed - the default is 10 at the moment - either 10, 25, 50 or all

The existing offending code

Code:
<?php $linesperpage = 10; $sea = @$_POST['search']; if (!$sea) $sea = @$_GET['sea']; $yr = @$_POST['year']; if (!$yr) $yr = @$_GET['yr']; $var = @$_GET['pag'] ; if (!$var) { $var=1; } $sort = @$_GET['sort'] ; if (!$sort) { $sort="artist"; } $db = mysql_connect("m*sq*0*.po*we*.com", "c*a*ag*r", "*ro*ve*id**"); mysql_select_db("hardcorewillneverdie",$db); if ($yr) { $result = mysql_query("SELECT * FROM archive WHERE year = '$yr' ORDER BY $sort",$db); $rs=$yr; } else { $result = mysql_query("SELECT * FROM archive WHERE artist LIKE '%$sea%' OR title LIKE '%$sea%' OR label LIKE '%$sea%' ORDER BY $sort",$db); $rs=$sea; } $rows = mysql_num_rows($result); $pages = ceil($rows / $linesperpage); if ($rows) { echo "<font color=#ffffff>Found $rows tunes for </font><b><font size=4 color=#ff9000>$rs</font></b>"; } else { echo "<font color=#ffffff>No tunes found</font>"; } echo "<br><br>"; if ($rows) { echo ""; echo ""; if ($var > 1) { $prev = $var -1; echo "<a href='$_SERVER[PHP_SELF]?sea=$sea&yr=$yr&pag=$prev&sort=$sort' STYLE='TEXT-DECORATION: NONE'>&lt&lt</a> "; } else { echo "&lt&lt "; } for ($i=1; $i<=$pages; $i++) { if ($i == $var) { echo "<font color=#ffffff>$i</font>"; } else { echo "<a href='$_SERVER[PHP_SELF]?sea=$sea&yr=$yr&pag=$i&sort=$sort'>$i</a>"; } echo " "; } if ($var < $pages) { $next = $var + 1; echo "<a href='$_SERVER[PHP_SELF]?sea=$sea&yr=$yr&pag=$next&sort=$sort' STYLE='TEXT-DECORATION: NONE'>&gt&gt</a>"; } else { echo "<font color=#ffffff>&gt&gt</font>"; } echo "<br>"; echo "<table cellpadding=3 border=0>\n"; echo "<tr><td></td><td></td><td></td><td><a href='$_SERVER[PHP_SELF]?sea=$sea&yr=$yr&sort=artist' STYLE='TEXT-DECORATION: NONE'>Artist</a>"; if ($sort=="artist") echo "<img src=sort.gif>"; echo "</td><td><a href='$_SERVER[PHP_SELF]?sea=$sea&yr=$yr&sort=title' STYLE='TEXT-DECORATION: NONE'>Title</a>"; if ($sort=="title") echo "<img src=sort.gif>"; echo "</td><td align=right><a href='$_SERVER[PHP_SELF]?sea=$sea&yr=$yr&sort=label' STYLE='TEXT-DECORATION: NONE'>Label</a>"; if ($sort=="label") echo "<img src=sort.gif>"; echo "</td><td align=right><a href='$_SERVER[PHP_SELF]?sea=$sea&yr=$yr&sort=cat' STYLE='TEXT-DECORATION: NONE'>Cat No</a>"; if ($sort=="cat") echo "<img src=sort.gif>"; echo "</td></tr>\n"; $start=($var-1) * $linesperpage; if (mysql_data_seek($result,$start)) { for ($i = 1; $i <= $linesperpage; $i++) { if ($myrow = mysql_fetch_row($result)) { echo "<tr><td>"; if ($myrow[5]) printf("<a href=%s>LABEL</a>", $myrow[5]); echo "</td><td>"; if ($myrow[6]) printf("<a href=%s>PLAY</a>", $myrow[6]); echo "</td><td>"; if ($myrow[7]) printf("<a href=%s>PLAY</a>", $myrow[7]); echo "</td>"; printf("<td><font color=#ffffff>%s</font></td><td><font color=#ffffff>%s</font></td><td align=right><font color=#ffffff>%s</font></td><td align=right><font color=#ffffff>%s</font></td></tr>\n", $myrow[0], $myrow[1], $myrow[2], $myrow[3]); } else { printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n"); } } } echo "</table>\n"; } ?>
It would also be handy if I could control the overall format through CCS. Again, my knowledge is limited here although some control does exist under my main CCS.

Appreciate there are a lot of "wants" here, but really, any help or support would be greatly appreciated as google searches and research isn't helping much!

Thank you!

Be gentle!
HWND is offline   Reply With Quote
Old 5-4-12, 11:10 PM   #2
PeterPan
 
Join Date: Sep 2002
Location: Auckland
Posts: 1,227
Reputation: 59
i'm not sure of the rest, but you may want to use the PHP REQUEST function, instead of post and get.

http://www.w3schools.com/php/php_post.asp
PeterPan is offline   Reply With Quote
Old 5-8-12, 07:58 AM   #3
HWND
Registered
 
Join Date: May 2012
Location: Cardiff
Posts: 2
Reputation: 0
Quote:
Originally Posted by PeterPan View Post
i'm not sure of the rest, but you may want to use the PHP REQUEST function, instead of post and get.

http://www.w3schools.com/php/php_post.asp
Thanks for your response. Not sure what difference it would make though?

The other stuff - no takers? I'm guessing it's outside the usual realms of free advice, it is complicated to me anyways!?
HWND is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:34 AM.


Contents ©PowWeb, Inc. ~ vBulletin, Copyright © 2000-2007 Jelsoft Enterprises Limited.