We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12557
    • 2 Posts
    I inherited a ModX web site. One of my site’s pages (http://promiseofplace.org/calendar) uses a php snippet to perform a search of the calendar events by organization, season, or state. I would like to modify this search to return ONLY events that are active (active events are in the future...as events occur they are switched from active to inactive). I don’t know php.

    Can anyone help? The code is below:

    <?php
    //print_r($_POST);
     $FatQuery = "";
     if ($_POST['organization'] != ""){
      $FatQuery.=" AND organization LIKE '%".$_POST['organization']."%'"; 
     }  
     if ($_POST['season'] != "99"){
      $FatQuery.=" AND season = '".$_POST['season']."'"; 
     }   
     
      if ($_POST['state'] != "Any"){
      $FatQuery.=" AND state = '".$_POST['state']."'"; 
     }  
     
    
     
     $FatQuery = ltrim($FatQuery," AND");
     
     if ($FatQuery == "")
     {
     $FatQuery = "SELECT * FROM event";       
     }else{
     $FatQuery = "SELECT * FROM event WHERE ".$FatQuery;       
     }
     
      require '/home/content/p/r/o/promiseofplace/html/phpinc/config.php';   
    require "$conf[inc_dir]/db_utils.php";
    require "$conf[inc_dir]/functions.php";
    
    // Connect to the database.
    $dbh = db_connect ($conf['db_host'], $conf['db_name'], $conf['db_user'], $conf['db_pass']);
    
    
    $sth = db_query ($FatQuery);
      if ((mysql_num_rows($sth) > 0)){
    while ($row = db_fetch_assoc ($sth)) {
    
        $event_date = $row['event_date'];
    
         $season = $row['season'];  
         if ($season == "0"){
           $season_readable = "June/July/August";   
         }
          if ($season == "1"){
           $season_readable = "September/October/November";   
         }
              if ($season == "2"){
           $season_readable = "December/January/February";   
         }
              if ($season == "3"){
           $season_readable = "March/April/May";   
         }   
        
        $location = $row['location'];
    
        $title = $row['title'];
    
        $description = $row['description'];
    
        $fee = $row['fee'];
    
        $organization = $row['organization'];
    
        $first_name = $row['first_name'];
    
        $last_name = $row['last_name'];
    
        $address = $row['address'];
    
        $phone = $row['phone'];
    
        $email = $row['email'];
    
        $website = $row['website'];
    
         $state = $row['state'];   
        
        if ($email) {
    
            list ($email_user, $email_domain) = split ('@', $email);
    
        } else {
    
            $email_user = '';
    
            $email_domain = '';
    
        }
    
    
    
        ?>
            <style>
        .details th {
        position: absolute;
        left: -999em;
    }
    
    .details td {
        vertical-align: top;
        border-bottom: 1px solid #ccc;
        padding: 5px 5px 5px 0;
    }
    
    .details .label {
        color: #4B305D;
        width: 100px;
    }
    
    .details ul {
        padding: 0 0 0 15px;
    }
    
    /*
    Case Studies Search Results */
    
    .result h2, .result p {
        padding-bottom: 0;
    }
    
    .result h2 a:link { color: #4B305D; }
    .result h2 a:visited { color: #382446; }
    .result h2 a:hover { color: #786486; }
    .result h2 a:active { color: #000; }
    
    .result {
        padding-bottom: 20px;
    }
    
    .photo {
        float: left;
        padding: 0 20px 0 0;
    }
    </style>
    <script type="text/javascript"> 
    
      function email(alias,url,lnktext, subject){
        if (subject == "") {
            document.write ("<a href='mailto:" + alias + "@" + url + "' target='_blank'>" + lnktext + "</a>");
        } else {
            document.write ("<a href='mailto:" + alias + "@" + url + "?subject=" + subject + "' target='_blank'>" + lnktext + "</a>");
        }
    }
    </script>
    
     
        <div class="upcoming_event" id="event<?= $row['id'] ?>">
    
            <h4 class="title"><?= $title ?></h4>
            <h3 class="location">Season: <?= $season_readable ?>    <? if ($state != "") { echo "State: $state";} ?></h3>      
            
            <h3 class="date"><?= $event_date ?></h3>
    
    
            
            <h3 class="location"><?= $location ?></h3>
    
            <p class="description"><?= $description ?></p>    
    
    
    
    <? if ($fee || $organization || $first_name || $last_name || $address || $phone || $email || $website) { ?>
    
    
    
            <h3>Details & Contact Info</h3>
    
            <table summary="Details and Contact Person for this Event" cellspacing="0" class="details">
    
    
    
            <thead>
    
            <tr>
    
                <th id="label">Label</th>
    
                <th id="value">Value</th>
    
            </tr>
    
            </thead>
    
            
    
            <tbody>
    
            <? if ($fee) { ?>
    
            <tr>
    
                <td headers="label" class="label">Fee</td>
    
                <td headers="value"><?= $fee ?></td>
    
            </tr>
    
            <? } ?>
    
            <? if ($organization) { ?>
    
            <tr>
    
                <td headers="label" class="label">Organization</td>
    
                <td headers="value"><?= $organization ?></td>
    
            </tr>
    
            <? } ?>
    
            <? if ($first_name || $last_name) { ?>
    
            <tr>
    
                <td headers="label" class="label">Name</td>
    
                <td headers="value"><?= $first_name ?> <?= $last_name ?></td>
    
            </tr>
    
            <? } ?>
    
            <? if ($address) { ?>
    
            <tr>
    
                <td headers="label" class="label">Address</td>
    
                <td headers="value"><?= $address ?></td>
    
            </tr>
    
            <? } ?>
    
            <? if ($phone) { ?>
    
            <tr>
    
                <td headers="label" class="label">Phone</td>
    
                <td headers="value"><?= $phone ?></td>
    
            </tr>
    
            <? } ?>
    
            <? if ($email) { ?>
    
            <tr>
    
                <td headers="label" class="label">E-mail</td>
    
                <td headers="value"><script type="text/javascript">email('<?= $email_user ?>','<?= $email_domain ?>','<?= $email_user ?>'+'@'+'<?= $email_domain ?>','');</script><noscript><pre>Javascript must be enabled to view email addresses on this site</pre></noscript></td>
    
            </tr>
    
            <? } ?>
    
            <?
    
    
    
            if ($website) {
    
                if (! preg_match ("/^http/i", $website)) {
    
                    $website = "http://$website";
    
                }
    
            ?>
    
            <tr>
    
                <td headers="label" class="label">Website</td>
    
                <td headers="value"><a href="<?= $website ?>"><?= $website ?></a></td>
    
            </tr>
    
            <? } ?>
    
            </tbody>    
    
          </table>
    
    
    
    <? } ?>
    
    
    
        </div>
    
    
    
    <? } ?>
    
      <?
      }else{
       echo "Search returned no results.  Please <a href=javascript:history.go(-1)>go back</a> and try again.";   
      }
    ?>

      • 3749
      • 24,544 Posts
      You’ll have to look in the database using PhpMyAdmin in cPanel and look at the table that holds the calendar information. You need to find the name of the field that holds the "active" information and what’s in that field when the event is active. The field name may be ’active’ or something else.

      Once you know the active field, you can just add another "AND" condition to the query just below the $FatQuery = ""; line. Something like this:


      $FatQuery.=" AND active = '"1"'"; 






        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 12557
        • 2 Posts
        Thank you, BobRay, for your response.

        Unfortunately, I don’t know how to access the database (or cpanel for that matter) to see what fields are available.
          • 3749
          • 24,544 Posts
          This might be a good time to learn. wink

          cPanel is the control panel you see when you log in to your account at the hosting service. You should find PhpMyAdmin somewhere in the database section.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting