envexlabs Posted July 4, 2007 Share Posted July 4, 2007 alright, so i will give you all the code first, and then try to explain afterwards functions.php (included in index.php): function perform_search($search, $table, $c){ global $search_query; if($_GET[yellow] == 'on' && $_GET[white] == 'on') { //searches both white & yellow pages $search_query = mysql_query('SELECT * FROM `entries` WHERE `' . $table . '` LIKE "%' . $search .'%" ORDER BY `ID` ASC LIMIT ' . $c . ', 10') or die(mysql_error()); return $info; } elseif($_GET[yellow] == 'on') { //if yellow pages have been selected $search_query = mysql_query('SELECT * FROM `entries` WHERE `' . $table . '` LIKE "%' . $search .'%" AND `directory` = 1 ORDER BY `ID` ASC LIMIT ' . $c . ', 10') or die(mysql_error()); return $info; } elseif($_GET[white] == 'on') { //if white pages have been selected $search_query = mysql_query('SELECT * FROM `entries` WHERE `' . $table . '` LIKE "%' . $search .'%" AND `directory` = 0 ORDER BY `ID` ASC LIMIT ' . $c . ', 10') or die(mysql_error()); return $info; } else{ //searches both white & yellow pages $search_query = mysql_query('SELECT * FROM `entries` WHERE `' . $table . '` LIKE "%' . $search .'%" ORDER BY `ID` ASC LIMIT ' . $c . ', 10') or die(mysql_error()); return $info; } } function counter($table, $search){ global $count; global $page; global $counter; global $page_count; $count_query = mysql_query('SELECT COUNT(*) FROM `entries` WHERE `' . $table . '` LIKE "%' . $search .'%"') or die(mysql_error()); $count = mysql_result($count_query, 0); for ($counter = 0; $counter <= $count; $counter += 10) { $page = $counter; $page_count = $counter / 10; echo '<a href="?c=' . $page . '">' . $page_count . '</a> '; } return $count; } index.php: $c = 0 + $_GET[c]; $search = $_GET[search]; $table = $_GET[search_param]; $have_submitted = $_GET[have_submitted]; $white = $_GET[white]; $yellow = $_GET[yellow]; $info = perform_search($search, $table, $c); //creates the next and previous buttons to only show 10 messages if($c == 0) { //no previous button echo('Previous'); echo(" | "); counter($table, $search); echo(" | "); echo('<a href="?c=' . $c = $c + 10 .'&search=' . $search . '&search_param=' . $table . '&have_submmitted=' . $have_submitted . '&x=0&y=0&white=' . $white . '&yellow=' . $yellow . '">Next</a>'); } elseif($c >= $count) { //no next button echo('<a href="?c=' . ($c - 10) . '&search=' . $search . '&search_param=' . $table . '&have_submmitted=' . $have_submitted . '&x=0&y=0&white=' . $white . '&yellow=' . $yellow . '">Previous</a>'); echo(" | "); counter($table, $search); echo(" | "); echo('Next'); } else{ //all buttons echo('<a href="?c=' . ($c - 10) . '&search=' . $search . '&search_param=' . $table . '&have_submmitted=' . $have_submitted . '&x=0&y=0&white=' . $white . '&yellow=' . $yellow . '">Previous</a>'); echo(" | "); counter($table, $search); echo(" | "); echo('<a href="?c=' . ($c + 10) . '&search=' . $search . '&search_param=' . $table . '&have_submmitted=' . $have_submitted . '&x=0&y=0&white=' . $white . '&yellow=' . $yellow . '">Next</a>'); } //loops out all the entries while($info = mysql_fetch_row($search_query)) { echo $info[1]; } SO, i have a form on index.php that submits the values $search, $search_param, $have_submitted and either $yellow, or $white. this is the address bar from a search: index2.php?c=0&search=matt&search_param=fname&have_submitted=true&x=0&y=0&white=on The first shot, everything works fine, the names are generated out, and all is good. but when i click on the next button, to change $c to 10, the page refreshes and it renders out nothing. I think the problem is that the mySQL query in perform_search() isn't refreshing itself with the new values. What am i doing wrong? Thanks. Quote Link to comment Share on other sites More sharing options...
wcsoft Posted July 4, 2007 Share Posted July 4, 2007 What does the URL look like when you click the next button? Is it the same as the url you posted only with the value of c being altered? What happens if you manually change c from 0 to 10 in the address bar itself and load that page? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 4, 2007 Share Posted July 4, 2007 also some browsers are a little stagnet on updating gets and you actually have to click the url or refresh a page to get it to trigeer a change, also a good tip is to ehco out your query string so you can see it and see what the issue is Quote Link to comment Share on other sites More sharing options...
envexlabs Posted July 4, 2007 Author Share Posted July 4, 2007 Hey, the link is the same, just the $c value changed. If i manually enter it into the address bar, it works. So what can i do to fix this problem? i could store the values into a cookie, but that seems a bit messy. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 4, 2007 Share Posted July 4, 2007 on the form page did you check your source code to ensure that the source of $_GET['c'] is being properly valued? Quote Link to comment Share on other sites More sharing options...
envexlabs Posted July 4, 2007 Author Share Posted July 4, 2007 well, i feel like a REAL idiot. in the Next URL i added an extra M in have_submitted. seems to work now. thanks guys! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 4, 2007 Share Posted July 4, 2007 mark it solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.