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
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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