djdvine Posted April 7, 2008 Share Posted April 7, 2008 All, I am a newbie to PHP / MYSQL and for 2 months I have been trying to figure out how to paginate my new movie database I created. I have been able to figure it out when I don't have a "SUBMIT" button on a form (to search for certain criteria), but when the user enters a search term and hits "Next" on the hyperlink to go to the next page of results, it comes up blank. I believe the search term isn't carrying over for some reason. Below is my code, and I have taken off all of the pagination code I had, so I won't confuse anyone. Can someone PLEASE input the correct code in the correct spots so I can paginate the results? (10 items per page will be fine). Thanks in advance, this is KILLING ME! (Im using this for my personal movie database website http://daveallen33.com/movies/query.php) //BEGIN CODE// </FORM> echo"<input type=submit name=submit value=submit>"; echo "</FORM>"; $cast = $_GET['cast']; if ($_GET['cast'] =="") { echo "you did not enter any value in the search box"; exit(); } //MY SEARCH QUERY// if($cast != ""){ $query = "SELECT * FROM MAIN WHERE CAST LIKE \"%$cast%\" ORDER BY TITLE"; $result = mysqli_query($cxn,$query) or die ("NO YOU IDIOT"); $nrows = mysqli_num_rows($result); echo "<FONT COLOR=white>Actor Only</FONT></CENTER><br>"; if ($nrows >0){ echo "<center><img src=images/newang.jpg border=1><BR><BR>"; echo "<font size=5><font color=990033>So, You Want To See <font color=151B8D>$cast</font> ? Here Are <font color=151B8D>$nrows</font> of Dave's Movies to Choose From:</center></font><BR>"; echo "<font size=5><font color=white><b><center><a href=\"http://www.imdb.com/find?s=all&q=$cast\" target=_blank>See $cast's Other Movies</a></font></font color></b></center><br>"; } else { echo "<center><img src=images/thebotch.jpg border=2><BR><BR>"; echo "<font size=5><font color=990033>Your Search For <font color=151B8D>$cast</font> Came Up Empty, Try Again...<b>JackAss!</b></center></font><BR>"; } } while ($row = mysqli_fetch_assoc($result)){ $movie_id = $row['MOVIE_ID']; $cover_art= $row['COVER_ART']; $title= $row['TITLE']; $genre= $row['GENRE']; $year= $row['YEAR']; $length= $row['LENGTH']; $cast= $row['CAST']; $review= $row['REVIEW']; $director= $row['DIRECTOR']; $director= $row['DIRECTOR']; $summary= $row['SUMMARY']; echo "<table> <tr><td bgcolor=#660033><b><font color=yellow face=\"Georgia Bold\" size=6>$title (<i>$year</i>)</b></font><br><a href=trailers/movie_trailers/$movie_id.html><img align=left src=images/CoverArt/$cover_art border=3 alt=\"$title\"></a> <b><i><font face=arial color=#99FFFF size=4>$genre Film Directed by $director, and $length Long</i></b></font> <b> <img src=images/$review.gif><br><br> <b><font color=white face=arial size=4>SUMMARY:</font><font color=#FFFFCC size=4 face=arial> $summary</font><br><br> <b><font color=white face=arial size=4>CAST:</font><font color=#FFFFCC size=4 face=arial> $cast</font><br><br> </td></tr> <tr><td><hr size=5 align=center width=100% color=#FF3399> </tr></td></table>"; } ?> Again, thanks, if you have any questions, please feel free to email me Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/ Share on other sites More sharing options...
netphreak Posted April 7, 2008 Share Posted April 7, 2008 Not 100% certain, but I believe you must have a submit button to handle post data. You can't send any form data with a hyperlink, even if you use $_GET. Try styling your submit button instead With CSS you can make it look just as you want. Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-510972 Share on other sites More sharing options...
BillyBoB Posted April 7, 2008 Share Posted April 7, 2008 Please do your research before posting. If you need a pagination function I created one a while back that you could use if you would like. Just hit me up on AIM: BillyBoB66969 or MSN: [email protected] Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-510973 Share on other sites More sharing options...
djdvine Posted April 7, 2008 Author Share Posted April 7, 2008 Not 100% certain, but I believe you must have a submit button to handle post data. You can't send any form data with a hyperlink, even if you use $_GET. Try styling your submit button instead With CSS you can make it look just as you want. Forgive my ignorance, as I'm new to this, but I do have a submit button, it was the first line of code. Once the user hits the submit button, it executes the search. It's that search I'm trying to paginate. I'm not very confident with CSS just yet, I need to stick with HTML for now. Thanks... Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-510974 Share on other sites More sharing options...
djdvine Posted April 7, 2008 Author Share Posted April 7, 2008 Please do your research before posting. If you need a pagination function I created one a while back that you could use if you would like. Just hit me up on AIM: BillyBoB66969 or MSN: [email protected] Thanks for the reply, trust me, I have done tons of research on this subject. I just havent been able to find the right answer. I guess what I'm looking for is someone that knows what they are talking about to say "At Line 10, enter "blah blah blah" Sorry if I'm making this more difficult than it is.... Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-510976 Share on other sites More sharing options...
BillyBoB Posted April 7, 2008 Share Posted April 7, 2008 djdvine I wasn't speaking toward you on that one it was toward netphreak because his statement was very wrong.. just incase you want the function: <?php function pagination($h,$get,$page,$z) { $g = ceil($h/$z); $d = 0; $u = 0; $o = 0; if($g>1) { while($d!=$g) { $d++; if($get) { if($get==$g){ $c = $get - 4; if($c!=0) { $o = 1; } if($o==0) { $d = $get - 3; $o = 1; } if($d==$get) { echo("<b>[$d]</b>"); echo(" "); }else{ $c = $get - 4; if($c!=0) { echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); }else{ if($u==0) { echo("<a href=\"$page&pg=1\">1</a>"); echo(" ... "); $u = 1; }else{ echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); } } } }else{ if($d==$get) { echo("<b>[$d]</b>"); echo(" "); }else{ if($get==1) { if($d<4) { echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); }else{ echo("... <a href=\"$page&pg=$g\">$g</a>"); $d = $g; } }else{ $a = $get - 4; $b = $get + 2; if($a>0) { if($d==$get) { echo("<b>[$d]</b>"); echo(" "); }else{ if($u==0) { echo("<a href=\"$page&pg=1\">1</a>"); echo(" ... "); $u = 1; }else{ if($o==0) { $d = $get - 2; $o = 1; } if($get+3==$d) { if($b<$g-1) { echo(" ... "); echo("<a href=\"$page&pg=$g\">$g</a>"); $d = $g; }else{ echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); } }else{ echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); } } } }else{ if($get+3==$d) { if($b<$g-1) { echo(" ... "); echo("<a href=\"$page&pg=$g\">$g</a>"); $d = $g; }else{ echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); } }else{ echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); } } } } } }else{ if($d==1) { echo("<b>[$d]</b>"); echo(" "); }else{ if($d<4) { echo("<a href=\"$page&pg=$d\">$d</a>"); echo(" "); }else{ echo("... <a href=\"$page&pg=$g\">$g</a>"); $d = $g; } } } } }else{ echo("<b>[1]</b>"); } } ?> In order to make it work: Put this at the top before you are going to list the info make sure you edit correctly. This query is the one that you use to display the info below it. In your case the movies. <?php $h = 0; $paquery = mysql_query("SELECT * FROM table"); while($painfo = mysql_fetch_array($paquery)) { $h++; } if($_GET['pg']) { $pg = $_GET['pg'] * 20; $low = $pg - 20; $query = mysql_query("SELECT * FROM table LIMIT $low,20"); }else{ $query = mysql_query("SELECT * FROM table LIMIT 20"); } $i = 0; ?> Put this wherever you need to have the pages show up. Edit the members.php? to whatever your pagename is and the 20 is the limit per page edit as above also. (you need not worry about the $h or the $_get[pg] as long as you don't edit them above. <?php if(!$_POST[submitquery]){ pagination($h,$_GET['pg'],"members.php?",20); } ?> Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-510977 Share on other sites More sharing options...
djdvine Posted April 7, 2008 Author Share Posted April 7, 2008 djdvine I wasn't speaking toward you on that one it was toward netphreak because his statement was very wrong.. Oh, ok, thanks for the clarification. Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-510979 Share on other sites More sharing options...
djdvine Posted April 7, 2008 Author Share Posted April 7, 2008 Thanks for the code...I'll see what I can do with it...I'll let ya know.. Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-510982 Share on other sites More sharing options...
netphreak Posted April 7, 2008 Share Posted April 7, 2008 And I am sorry if I were wrong. Just trying to help. That's why I also wrote that I'm not sure about this. So it's not called a statement then? I'm no professional. Sorry, I will not post my believes in here again. Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-511027 Share on other sites More sharing options...
djdvine Posted April 7, 2008 Author Share Posted April 7, 2008 And I am sorry if I were wrong. Just trying to help. That's why I also wrote that I'm not sure about this. So it's not called a statement then? I'm no professional. Sorry, I will not post my believes in here again. No Prob Netphreak...I don't think we'd be on this board if we all weren't trying to get help from somewhere. I don't think anyone can be the total expert on this stuff. So...feel free to post your beliefs whenever you like, it's America baby! Link to comment https://forums.phpfreaks.com/topic/99923-newbie-with-pagination-help/#findComment-511087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.