Jump to content


Photo

#SOLVED# Filter Data and automatic Refresh


  • Please log in to reply
7 replies to this topic

#1 hphimmel

hphimmel
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationAustria, Oslip

Posted 13 June 2006 - 11:39 AM

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:

<?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>


The filtering part looks like this:
<?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>

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

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 June 2006 - 11:46 AM

YOU NEED AJAX! MATE


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 hphimmel

hphimmel
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationAustria, Oslip

Posted 14 June 2006 - 06:10 AM

[!--quoteo(post=383211:date=Jun 13 2006, 01:46 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 13 2006, 01:46 PM) View Post[/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 suggestion

Henry

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 14 June 2006 - 06:44 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 hphimmel

hphimmel
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationAustria, Oslip

Posted 14 June 2006 - 06:22 PM

[!--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) View Post[/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.



#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 June 2006 - 06:25 PM

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!

#7 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 14 June 2006 - 07:00 PM

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.
/*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";
  }
}

Then build your sql statement

/* Generate Table Listings */
$sql =  "SELECT what.* FROM here";
$sql .= "WHERE siteID = 'AA'";
$sql .= $_PAGE_SPECIFIC['filters']; // apply filters
$sql .= " ORDER BY stuff,morestuff";


Build your Form this way:
<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>



#8 hphimmel

hphimmel
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationAustria, Oslip

Posted 15 June 2006 - 09:47 AM

[!--quoteo(post=383950:date=Jun 14 2006, 09:00 PM:name=lead2gold)--][div class=\'quotetop\']QUOTE(lead2gold @ Jun 14 2006, 09:00 PM) View Post[/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 Austria

Henry




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users