Jump to content

Recommended Posts

Hi everyone,
 
I would like to know if:

 

 
I have three different forms to create three different mysql codes.
Now my code will generate the three mysql codes correctly but each time I tried to generate the second mysql code using another form, the previous will get wiped and therefore I can only have one mysql code working at the moment. 
 
(I apologize in advanced if my issue is not clearly stated.)

 

Attached is the code that I have right now. I am trying to get all three mysql codes (Searchsql, Filtersql, Panelsql) correct so I can pass all three mysql queries to a function where it can combine all three queries into one array using the array_intersect function.

 

Please kindly let me know your opinion on the problem and I would really appreciate the help.

$object = new Three;
class Three
{
    public $Panel, $Search, $Filter;
    function save_Three()
    {
        while($Prow = sqli_fetch_array($Panel, MYSQLI_BOTH))
        {
            $PanelName = $Prow ['name'];
        }
        while($Srow = sqli_fetch_array($Search, MYSQLI_BOTH))
        {
            $SearchName = $Srow ['name'];
        }
        while($Frow = sqli_fetch_array($Filter, MYSQLI_BOTH))
        {
            $FilterName = $Frow ['name'];
        }
        $Combined = array_intersect($Panel, $Search, $Filter);
        foreach ($Combined as $item)
            print $item;
    }
}

$Panelsql = "SELECT DISTINCT aID, name from test.article";

if (isset($_GET['pid']))
{
    $pID= $_GET['pid'];
    echo "$pID";

    $Panelsql = "SELECT DISTINCT aID, name from test.a_m, test.platform, test.message, test.article where aid in 
    (SELECT DISTINCT assocAID from test.a_m, test.platform, test.message where assocMID in
    (SELECT mID from test.message, test.platform where pID=$pID and pID = assocPID))";

}
else if (isset($_GET['mid']))
{
    $mID= $_GET['mid'];

    
    $Panelsql = "SELECT DISTINCT aID, name from a_m, message, article where aid in 
    (SELECT DISTINCT assocAID from a_m, message where mID=$mID and mID = assocMID)";
}
else
{   
    $Panelsql = "SELECT DISTINCT aID, name from article";
}

$object->Panel = $Panelsql;

$aRegions = $_POST['RegionSelected'];
$Filtersql = 'SELECT * FROM test.article';
if(isset($aRegions))
{
    $Filtersql .= ' WHERE 1 AND ('; 
    foreach ($aRegions as $word) 
    if($word==$aRegions[count($aRegions)-1])
    {
        $Filtersql .= " Region = '". $word ."')";
    }
    else
    {
        $Filtersql .= " Region = '". $word ."' OR";
    }
}
//Population filtering function
$aPopulations = $_POST['PopulationSelected'];
if(isset($aPopulations))
{
    if(!isset($aRegions)){$Filtersql .= ' WHERE 1 AND ('; }
    else
    {
        $Filtersql .= ' AND (';
    } 
    foreach ($aPopulations as $word) 
    if($word==$aPopulations[count($aPopulations)-1])
    {
        $Filtersql .= " Population = '". $word ."')";
    }
    else
    {
        $Filtersql .= " Population = '". $word ."' OR";
    }       
            
}

$object->Filter = $Filtersql;


$Searchsql="SELECT * FROM test.article";

if (isset($_POST['search'])){
    
    $st= ($_POST['search_box']);
    $Searchsql .= " WHERE name LIKE '%{$st}%' OR abstract LIKE '%{$st}%' OR Summary LIKE '%{$st}%' OR Keyword LIKE '%{$st}%'
    OR population LIKE '%{$st}%'OR region LIKE '%{$st}%'";
}
$object->Search = $Searchsql;


Just taking a shot at what I think you are doing. 

 

Form 1 is displayed and submitted and you grab the first value.  Then I assume that you generate a new form and the same process happens and you grab the second value, but lose the first. 

 

1 - you could save the first value as a hidden form field in the second form and then retrieve both when the second form is submitted.

2 - OR you could save each form value as a $_SESSION variable and when all 3 forms are done you will have 3 session vars to use at the end.

The first option - a hidden field - is nothing more than adding one of these to your next form before output:

<input type='hidden' name='field1' value='$field1'>

Then when your second form is subtmitted and you receive the POST vars, you will have a $_POST['field1'] in it.  Then you send that back out with the field you are getting in your second form, both to the third form. 

Edited by ginerjm

Hi, I used the $_SESSION variable to store all three of my variables and everything works fine except when I refresh the page, the variables are still there.

 

I would like to know if there is a way to use the session_unset/destroy function so that every time the page is refreshed, the SESSION variables will reset.

 

Thanks!

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.