hphimmel Posted June 13, 2006 Share Posted June 13, 2006 Hello!Desperate programmer here. I would like to show Filter in a Dropdown list. If user changes it, the page should refresh by itself.If nothing is choosen, a standard query is set. This works (ok, is on the first run).I do not have problems with Database. I can connect, I am able to set queries and they work.What I tried, is this:[code]<?php session_start(); #hier Sessionauthorisierung mitsenden # Berechtigungsmapping abholen/get Permissionmapping from database (rwx) #include("../berechtigungskopf.inc.php"); # ---------------------------------------------------- # # Ab hier Daten gemäß der Aufgabe abfragen/get server,user,password include("../dbdata.inc.php"); @mysql_connect($server, $username, $password); # Datenbankverbindung aufnehmen/get connection @mysql_select_db($database) or die("Kann nicht mit Berechtigungsdatenbank verknüpfen"); # Abfrage absetzen ----------------------------------- # if (!empty($_SESSION['subquery'])) { if ($_SESSION['subquery']=='FilterFamilienname') { $_SESSION['subquery'] =' ORDER BY Name'; } # standard $query="SELECT * FROM vw_Facharzt".$_SESSION['subquery']; } else { $query="SELECT * FROM vw_Facharzt"; } # ---------------------------------------------------- # # and so on# now would come the grid and the many fields... again: NO prob. ?><html><head><title>dynamic filter test</title></head><body><script language="javascript" type="text/javascript"> function hprocess(Filter) { subquery=Filter; if (Filter=="FN") { subquery=" ORDER BY 'NAME'"; } if (Filter=="FP") { subquery=" ORDER BY 'PLZ'"; } // etc alert(subquery); // just for testing and it works! }</script>[/code]The filtering part looks like this:[code]<?php $filterarten = array( "FL"=>"", "FN"=>"Familienname", "FP"=>"Postleitzahl", "FR"=>"Fachrichtung", "FM"=>"Mitglieder", "FI"=>"Mitglieder Inland", "FA"=>"Mitglieder Ausland", "FE"=>"Ehrenmitglieder", "FD"=>"Diplomierte" );?><p> <form name="Filterform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <select name="Filter" size="1" onChange="hprocess(this.form.Filter.options[this.form.Filter.selectedIndex].value)"> <?php foreach ($filterarten as $key=>$element) { echo "<option value=$key>$element</option>"; } ?> </select></p></form></body></html>[/code]Is there any hint, how I could manage it, that the filter (=subquery) is done on the same page - or it calls itself again with the right query.subquery combination?Any suggestion? Anyone out there?Hello?Thanks a lot for Your patience ...Henry Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/ Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 YOU NEED AJAX! MATE Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/#findComment-44967 Share on other sites More sharing options...
hphimmel Posted June 14, 2006 Author Share Posted June 14, 2006 [!--quoteo(post=383211:date=Jun 13 2006, 01:46 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 13 2006, 01:46 PM) [snapback]383211[/snapback][/div][div class=\'quotemain\'][!--quotec--]YOU NEED AJAX! MATE[/quote]AJAX is the name of a cleaning material in plastic bottles (in Austria) - I think, You mean something else [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] .My provider has no AJAX, so my intention is good, but that is all.Thanks for suggestionHenry Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/#findComment-45382 Share on other sites More sharing options...
.josh Posted June 14, 2006 Share Posted June 14, 2006 no he really does mean AJAX. it is a javascript method of updating content "live" without having to submit and refresh the whole page. Go to www.ajaxfreaks.com for more details. Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/#findComment-45393 Share on other sites More sharing options...
hphimmel Posted June 14, 2006 Author Share Posted June 14, 2006 [!--quoteo(post=383652:date=Jun 14 2006, 08:44 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 14 2006, 08:44 AM) [snapback]383652[/snapback][/div][div class=\'quotemain\'][!--quotec--]no he really does mean AJAX. it is a javascript method of updating content "live" without having to submit and refresh the whole page. Go to www.ajaxfreaks.com for more details.[/quote]Well, thanks to both of you. I took a look on their page and it looks strange and broken. So I believe, that AJAX does not look the same on every computer, so I let the fingers from that (knowing the different sort of browser of my comrades...). Maybe the ajaxfriends do have other stylish probs...?One more thing: I took my time now and looked over the tutorials more intensly. There is a lot of stuff and very good as I can say now. Congratulation. I love to learn but sometimes time is a pressure and ideas and technique do not match as easy as I want to. But ok. Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/#findComment-45666 Share on other sites More sharing options...
trq Posted June 14, 2006 Share Posted June 14, 2006 A simple Ajax tutorial [a href=\"http://marc.theaimsgroup.com/?l=php-general&m=112198633625636&w=2\" target=\"_blank\"]here[/a]. Written by the guy who invented php too! Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/#findComment-45669 Share on other sites More sharing options...
lead2gold Posted June 14, 2006 Share Posted June 14, 2006 I don't think AJAX is required... i'm doing what you want with PHP mixed with a FORM and a bit of Javascript.I only use Javascript for the auto-reload of the page once the item is selected.See what you want in action at: [a href=\"http://hitech.lead2gold.org/view_teams.php\" target=\"_blank\"]http://hitech.lead2gold.org/view_teams.php[/a]Here is a sample how i did 1 of the filters... it's based on building the where clause on the fly.[code]/*put this code in the upper section of your site *//* Filters are saved to a session variable for smart memory feature */if(isset($_FORM['tier_id'])){ if($_FORM['tier_id']){ $_SESSION['ftier_id'] = $_FORM['tier_id']; // store $_PAGE_SPECIFIC['filters'] .= " AND (t2s.tier_id = '".setDBvar($_FORM['tier_id'])."')"; $p_info[sizeof($p_info)] = "Tier filter is on"; }else{ unset($_SESSION['ftier_id']); }}else{ if(isset($_SESSION['ftier_id'])){ $_FORM['tier_id'] = $_SESSION['ftier_id']; $_PAGE_SPECIFIC['filters'] .= " AND (t2s.tier_id = '".setDBvar($_FORM['tier_id'])."')"; $p_info[sizeof($p_info)] = "Tier filter is on"; }}[/code]Then build your sql statement[code]/* Generate Table Listings */$sql = "SELECT what.* FROM here";$sql .= "WHERE siteID = 'AA'";$sql .= $_PAGE_SPECIFIC['filters']; // apply filters$sql .= " ORDER BY stuff,morestuff";[/code]Build your Form this way:[code]<form name="filters" id="filters" action="<?=$_SERVER['PHP_SELF'] ?>" method="get"> <select name="tier_id" id="tier_id" onchange="document.filters.submit(); return true;"> <option value="">-- All Tiers --</option> <?php $result = db_query("SELECT tier.tier_id,tier.name FROM tier ORDER BY tier.name"); while(($row = mysql_fetch_array ($result))){ ?> <option value="<?= $row['tier_id'];?>" <?php if($_FORM['tier_id'] == $row['tier_id']){echo "selected=\"selected\"";} ?> > <?= $row['name']; ?> </option> <?php } // end for() loop ?> </select></form>[/code] Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/#findComment-45679 Share on other sites More sharing options...
hphimmel Posted June 15, 2006 Author Share Posted June 15, 2006 [!--quoteo(post=383950:date=Jun 14 2006, 09:00 PM:name=lead2gold)--][div class=\'quotetop\']QUOTE(lead2gold @ Jun 14 2006, 09:00 PM) [snapback]383950[/snapback][/div][div class=\'quotemain\'][!--quotec--]I don't think AJAX is required... i'm doing what you want with PHP mixed with a FORM and a bit of Javascript.I only use Javascript for the auto-reload of the page once the item is selected.See what you want in action at: [a href=\"http://hitech.lead2gold.org/view_teams.php\" target=\"_blank\"]http://hitech.lead2gold.org/view_teams.php[/a][/quote]Thank You, @lead2gold! You really leaded to gold and saved my day! I accomplished the task with my DB and my filters, but it works. One more thing: I guess, in Your SELF_PHP code (form... action= ... ) You have one equal-sign too much. That was exactly what I needed. As I am still learning PHP adding AJAX would be a little bit too challenging; it is not dead for me, but it is not the right time.A nice day from AustriaHenry Link to comment https://forums.phpfreaks.com/topic/11858-solved-filter-data-and-automatic-refresh/#findComment-45845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.