Jump to content

[SOLVED] cant make it remeber


spooke2k

Recommended Posts

idea is to do a check see if a button beens clicked if it has then do the required querywhich works fine except for fact i am using pagenation as well and the query on a re run thinks its first time its been run and runs default query  which works by a php self.  i just want to check if the radio button is clicked remeber it if it has and then re run same query and also check if its changed radio button if has do that query instead but im getting myself confussed there must be a better way than what im doing it or trying to do it tbe. 

 

either way dont work and i need to remeber it and check if the radio button is same as last time.

 

thanks in advance i know code has gone spagetti so opologies

 

 

$searchfield = $_POST[textfield];

 

if ($searchfield == "Search Criteria")

{

$searchfield ="";

}

 

if ($searchfield <> "")

{

$query  =  "select * from pressimagelink where details like '%".$searchfield."%' order by productcode asc LIMIT $offset,$rowsPerPage";

$query1  = "SELECT count(*) as total FROM pressimagelink where details like '%".$searchfield."%'";

    $_SESSION['query'] = $query;

$_SESSION['query1'] = $query1;

 

}else{

$oldinfo = $_POST['group1'];

if ($oldinfo == "")

{

$cat = "1";

}else{ 

$cat = ($_POST['group1']);

}

   

if ($_SESSION['query']=='') {

 

$query  = "select * from pressimagelink where Cat = '".$cat."' order by productcode asc LIMIT $offset, $rowsPerPage";

  $query1  = "SELECT count(*) as total FROM pressimagelink where Cat = '".$cat."'";

}else{

$query = $_SESSION['query'];

$query1= $_SESSION['query1'];

}

}

Link to comment
https://forums.phpfreaks.com/topic/55128-solved-cant-make-it-remeber/
Share on other sites

You don't state which field is the radio button, so I'm not going to read through the code and try to decipher. But, you could use one of three methods to remember the radio button: session variables, cookies, or on the query string (i.e. $_GET). i would suggest using session data or the query string.

 

Here is an example of how you could do it:

 

<?php

if (isset($_POST['radioField']) && $_POST['radiofield']=="thevalue") {

    //set variable switch
    $radio_option = true;
    $_SESSION['radioField'] = true;

} else if($_SESSION['radioField'] == true) {

    $radio_option = true;

} else {

    $radio_option = false;

}


if ($radio_option == true) {

  //Do query for the checked option

} esle {

  //Do the default query

}

?>

thanks for demo

 

if (isset($_POST['group1']) && $_POST['group1']=="wildlife") {

 

    //set variable switch

    $radio_option = true;

    $_SESSION['radioField'] = true;

 

} else if($_SESSION['radioField'] == true) {

 

    $radio_option = true;

 

} else {

 

    $radio_option = false;

 

}

 

if ($radio_option == true) {

 

$query = $_SESSION['query'] ;

$query1 = $_SESSION['query1'];

} else {

 

$query  = "select * from pressimagelink where Cat = '".$cat."' order by productcode asc LIMIT $offset, $rowsPerPage";

$query1  = "SELECT count(*) as total FROM pressimagelink where Cat = '".$cat."'";

$_SESSION['query'] = $query;

$_SESSION['query1'] = $query1;

}

}

 

thanks again and sorry to be pain.

 

 

 

 

it doesnt seem to work but as i showed i  think its something to do with my declarations of how i assign the querys i may be wrong im from a client side programming and server side seems to me very different.

 

but alas as i showed it doesnt seem to work there is 6 radio buttons all named group1 thanks again

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.