Jump to content

Phantaz

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by Phantaz

  1. Thank you for your reply markowe. I did plug those valves in as you suggest, but the $button or $search still throws me into a loop because neither of those variables are not being submitted when the paginations are clicked. Or maybe I am just not understanding you logic... I know there is a lot of issues with my code, and I am going to go back and optimize and secure it. Thanks for the tips, I will look into fixing those...
  2. Greetings All! New to PHP, and trying to learn as much as I can as quickly as I can for a client. I have been following some of Tutorials i understand most of it, but I still don't understand a few of the functions. Anyways, here is my problem. I am trying to combined the two tutorials (Pagination and Search Internal) but I seem to have myself in a loop... Code is as follows: <?php $connect = mysql_connect("localhost","root","~~~~"); $db = mysql_select_db("~~~"); $button = $_GET['submit']; $search = $_GET['search']; if ($button) { if (strlen($search)<=0) echo "Please enter a keyword"; else { //explode our search terms $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "keywords LIKE '%$search_each%' OR vid_state LIKE '%$search_each%' OR users LIKE '%$search_each%' OR title LIKE '%$search_each%'"; else $construct .= " OR keywords LIKE '%$search_each%' OR vid_state LIKE '%$search_each%' OR users LIKE '%$search_each%' OR title LIKE '%$search_each%'"; } //eco out construct $construct = "SELECT * FROM video_url WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); //max display per page $per_page = 3; //get start variable $start = $_GET['start']; //count records $record_count = $foundnum; //count max pages $max_pages = $record_count / $per_page; //may come out as decimal $pagenumbers = intval($max_pages) + 1; if (!$start) $start = 0; //setup previous and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='searchvideos.php?start=$prev'><img src='../images/texts/previous.png' border='0'></a> "; //show next button if (!($start>=$record_count-$per_page)) echo " <a href='searchvideos.php?start=$next'><img src='../images/texts/next.png' border='0'></a>"; //set variable for first page $i=1; for ($y=0;$y<$record_count;$y=$y+$per_page) { if($start!=$y) echo " <a href='searchvideos.php?start=$y'><span class='searchtext'>$i</span></a>"; else echo " <a href='searchvideos.php?start=$y'><span class='searchtext'> <font size='+1'><b>$i</b></font></span></a>"; $i++; } //show page numbers echo " / <font color='#FF6600' size='-1'>$pagenumbers</font> </td> <td align='right' width='50%'> <form action='../pages/searchvideos.php' method='get'> <span class='searchtext'>Search Videos</span> <input name='search' type='text' value='by Keywords, Title, Name, or State' size='35' /><input type='submit' name='submit' value='search' /> </form> </td> </tr> </table> </div> <br /><br /><div class='videotitle'><span class='createtext'> Videos </span></div> <br /><br />"; if ($foundnum==0) echo "No results found."; else { echo "$foundnum results found!<br><br>"; $query = mysql_query("SELECT * FROM video_url ORDER BY RAND() LIMIT $start, $per_page"); while($row = mysql_fetch_array($query)) //while ($numrows = mysql_fetch_assoc($run)) { $title = $row['title']; $url = $row['url']; $state = $row['vid_state']; $users = $row['users']; echo " <table bgcolor='#191919' cellpadding='0' cellspacing='0' background='../images/videobgs.png' align='center'> <tr> <td width='10px'></td> <td width='440px' height='370px' rowspan='6'> $url </td> <td width='340px' align='left'> <span class='createtext'>$title</span><hr /> $users<br /> $state </td> <td width='5px'></td> </tr> <tr><td> </td></tr> <tr><td> </td></tr> </table><br />"; } } } } ?> I know my code is dirty, and I have a lot to learn, and that I should probably be doing this a different way, but please try to correct the way I have it. Anyways..first page loads great, the search works great, the pagination works as it should (correct pages, correct page numbers, etc.). However, once I click on the "next" or the next "number" the next page is blank because the very first if statement throws a kink in my code... if ($button) - when continuing to the next page, a "$button" is not pressed and therefore doesn't continue the code, leaving the page blank. Any clues on how to fix this? I have tried combining the two in many different ways, this is the best i got so far... Thanks in advance, Phantaz
×
×
  • 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.