Jump to content

[SOLVED] massive get value problems


envexlabs

Recommended Posts

alright, so i will give you all the code first, and then try to explain afterwards :P

 

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.

 

Link to comment
https://forums.phpfreaks.com/topic/58422-solved-massive-get-value-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.