Cyjm1120 Posted November 7, 2014 Share Posted November 7, 2014 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; Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/ Share on other sites More sharing options...
ginerjm Posted November 7, 2014 Share Posted November 7, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496052 Share on other sites More sharing options...
Cyjm1120 Posted November 8, 2014 Author Share Posted November 8, 2014 Thank you so much for your advice. I would certainly learn about those two options and try to apply them into my code. Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496060 Share on other sites More sharing options...
ginerjm Posted November 8, 2014 Share Posted November 8, 2014 (edited) 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 November 8, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496061 Share on other sites More sharing options...
Cyjm1120 Posted November 10, 2014 Author Share Posted November 10, 2014 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! Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496267 Share on other sites More sharing options...
Barand Posted November 10, 2014 Share Posted November 10, 2014 Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496270 Share on other sites More sharing options...
Cyjm1120 Posted November 10, 2014 Author Share Posted November 10, 2014 Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496273 Share on other sites More sharing options...
Barand Posted November 10, 2014 Share Posted November 10, 2014 The whole point of using SESSION variables is so that the values persist from page to page. Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496275 Share on other sites More sharing options...
ginerjm Posted November 10, 2014 Share Posted November 10, 2014 In other words - if you are TRULY using $_SESSION vars then they are NOT on your page so you are NOT seeing them. Quote Link to comment https://forums.phpfreaks.com/topic/292347-how-to-save-three-variables-from-different-queries/#findComment-1496276 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.