[PHP] Inserire piu campi di ricerca

T4MAR4

Nuovo Utente
3 Lug 2017
10
0
1
39
Allora spero che mi aiuterete voi che siete degli esperti... ho scaricato uno script che lavora con js in php, per ricercare utenti nel database, e fin qui funziona perfettamente, il punto e che non riesco a far lavorare insieme ai campi del modulo la ricerca, se un utente mette nella textarea il nome utente lo ricerca se clicco ascendente o desc mi ricerca gli utenti nella lista in base al nome, ma ecco l inghippo, se inserisco un campo femmina o maschio non riesco a far visualizzare il nome di ricerca ad esempio mario insieme al campo maschio, mi visualizza sia maschio e femmina, lo script ha veramente pochissimi fili li posto:
getData.php
PHP:
<?php

if(isset($_GET['page'])){
    //Include pagination class file
    include('Pagination.php');
    
    //Include database configuration file
    include('dbConfig.php');
    
    $start = !empty($_GET['page'])?$_GET['page']:0;
    $limit = 25;
     //set conditions for search
    $whereSQL = $orderSQL = '';
    $keywords = $_GET['keywords'];
    $keyname = $_GET['keyname'];
    $sortBy = $_GET['sortBy'];

    if(!empty($keyname)){
        $whereSQL = "WHERE name LIKE '%".$keyname."%'";
    }
          elseif(!empty($keywords)){
        $whereSQ = "WHERE member_group_id LIKE '".$keywords."'";
    }

    if(!empty($sortBy)){
        $orderSQL = " ORDER BY name ".$sortBy;
    }else{
        $orderSQL = " ORDER BY name DESC ";
    }

    //get number of rows
    $queryNum = $db->query("SELECT COUNT(*) as name FROM ILFREE_core_members ".$whereSQL.$whereSQ.$orderSQL);
    $resultNum = $queryNum->fetch_assoc();
    $rowCount = $resultNum['name'];

    //initialize pagination class
    $pagConfig = array(
        'currentPage' => $start,
        'totalRows' => $rowCount,
        'perPage' => $limit,
        'link_func' => 'searchFilter'
    );
    $pagination =  new Pagination($pagConfig);
    
    //get rows
    $query = $db->query("SELECT * FROM ILFREE_core_members $whereSQL $whereSQ $orderSQL LIMIT $start,$limit");

    if($query->num_rows > 0){ ?>
        <div class="GETs_list">
        <?php
while($row = $query->fetch_assoc()){
$GroupID = $row["member_group_id"];
$IDgroup = array('29','77','62','83','46','43','73','58','68','2','78','63','82','45','42','71','52','67','27','76','60','81','44','41','70','56','65');
$GETID = $row['member_id'];
$Name = $row["name"];
$photo = $row["pp_main_photo"];
$bannato = '7';


?>
<div class="list_item">
<?php
// name

echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '"  title="Visualizza il profilo di ' . $Name . '" ><h2>' . $Name . '</h2></a>';

// foto
if(empty($photo)) { if(in_array($GroupID, $IDgroup)) {
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/file/search_femmina.png"/></a>'; }
elseif ($bannato == $GroupID) {
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/file/ban.png"/></a>'; }
else {
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/file/search_maschio.png"/></a>'; } }
else{
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/profile_photos/' . $photo . '"/></a>';
}








?>






    
          


            

            
            </div>
        <?php } ?>
        </div>
        <?php echo $pagination->createLinks(); ?>
<?php } } ?>
 

T4MAR4

Nuovo Utente
3 Lug 2017
10
0
1
39
dbConfig.php
PHP:
<?php
// Database configuration
$dbHost     = "9";
$dbUsername = "S";
$dbPassword = "6";
$dbName     = "xx";

// Create database connection
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

// Check connection
if ($db->connect_error) {
    die("Connection failed: " . $db->connect_error);
}
?>
Pagination.php
PHP:
<?php
/**
 * CodexWorld is a programming blog. Our mission is to provide the best online resources on programming and web development.
 *
 * This Pagination class helps to integrate ajax pagination in PHP.
 *
 * @class        Pagination
 * @author        CodexWorld
 * @link        http://www.codexworld.com
 * @contact        http://www.codexworld.com/contact-us
 * @version        1.0
 */
class Pagination{
    var $baseURL        = '';
    var $totalRows      = '';
    var $perPage         = 10;
    var $numLinks        =  3;
    var $currentPage    =  0;
    var $firstLink       = '&lsaquo; First';
    var $nextLink        = '&gt;';
    var $prevLink        = '&lt;';
    var $lastLink        = 'Last &rsaquo;';
    var $fullTagOpen    = '<div class="pagination">';
    var $fullTagClose    = '</div>';
    var $firstTagOpen    = '';
    var $firstTagClose    = '&nbsp;';
    var $lastTagOpen    = '&nbsp;';
    var $lastTagClose    = '';
    var $curTagOpen        = '&nbsp;<b>';
    var $curTagClose    = '</b>';
    var $nextTagOpen    = '&nbsp;';
    var $nextTagClose    = '&nbsp;';
    var $prevTagOpen    = '&nbsp;';
    var $prevTagClose    = '';
    var $numTagOpen        = '&nbsp;';
    var $numTagClose    = '';
    var $anchorClass    = '';
    var $showCount      = true;
    var $currentOffset    = 0;
    var $contentDiv     = '';
    var $additionalParam= '';
    var $link_func      = '';
    
    function __construct($params = array()){
        if (count($params) > 0){
            $this->initialize($params);       
        }
        
        if ($this->anchorClass != ''){
            $this->anchorClass = 'class="'.$this->anchorClass.'" ';
        }   
    }
    
    function initialize($params = array()){
        if (count($params) > 0){
            foreach ($params as $key => $val){
                if (isset($this->$key)){
                    $this->$key = $val;
                }
            }       
        }
    }
    
    /**
     * Generate the pagination links
     */   
    function createLinks(){
        // If total number of rows is zero, do not need to continue
        if ($this->totalRows == 0 OR $this->perPage == 0){
           return '';
        }

        // Calculate the total number of pages
        $numPages = ceil($this->totalRows / $this->perPage);

        // Is there only one page? will not need to continue
        if ($numPages == 1){
            if ($this->showCount){
                $info = 'Showing : ' . $this->totalRows;
                return $info;
            }else{
                return '';
            }
        }

        // Determine the current page   
        if ( ! is_numeric($this->currentPage)){
            $this->currentPage = 0;
        }
        
        // Links content string variable
        $output = '';
        
        // Showing links notification
        if ($this->showCount){
           $currentOffset = $this->currentPage;
           $info = 'Showing ' . ( $currentOffset + 1 ) . ' to ' ;
        
           if( ( $currentOffset + $this->perPage ) < ( $this->totalRows -1 ) )
              $info .= $currentOffset + $this->perPage;
           else
              $info .= $this->totalRows;
        
           $info .= ' of ' . $this->totalRows . ' | ';
        
           $output .= $info;
        }
        
        $this->numLinks = (int)$this->numLinks;
        
        // Is the page number beyond the result range? the last page will show
        if ($this->currentPage > $this->totalRows){
            $this->currentPage = ($numPages - 1) * $this->perPage;
        }
        
        $uriPageNum = $this->currentPage;
        
        $this->currentPage = floor(($this->currentPage/$this->perPage) + 1);

        // Calculate the start and end numbers.
        $start = (($this->currentPage - $this->numLinks) > 0) ? $this->currentPage - ($this->numLinks - 1) : 1;
        $end   = (($this->currentPage + $this->numLinks) < $numPages) ? $this->currentPage + $this->numLinks : $numPages;

        // Render the "First" link
        if  ($this->currentPage > $this->numLinks){
            $output .= $this->firstTagOpen
                . $this->getAJAXlink( '' , $this->firstLink)
                . $this->firstTagClose;
        }

        // Render the "previous" link
        if  ($this->currentPage != 1){
            $i = $uriPageNum - $this->perPage;
            if ($i == 0) $i = '';
            $output .= $this->prevTagOpen
                . $this->getAJAXlink( $i, $this->prevLink )
                . $this->prevTagClose;
        }

        // Write the digit links
        for ($loop = $start -1; $loop <= $end; $loop++){
            $i = ($loop * $this->perPage) - $this->perPage;
                    
            if ($i >= 0){
                if ($this->currentPage == $loop){
                    $output .= $this->curTagOpen.$loop.$this->curTagClose;
                }else{
                    $n = ($i == 0) ? '' : $i;
                    $output .= $this->numTagOpen
                        . $this->getAJAXlink( $n, $loop )
                        . $this->numTagClose;
                }
            }
        }

        // Render the "next" link
        if ($this->currentPage < $numPages){
            $output .= $this->nextTagOpen
                . $this->getAJAXlink( $this->currentPage * $this->perPage , $this->nextLink )
                . $this->nextTagClose;
        }

        // Render the "Last" link
        if (($this->currentPage + $this->numLinks) < $numPages){
            $i = (($numPages * $this->perPage) - $this->perPage);
            $output .= $this->lastTagOpen . $this->getAJAXlink( $i, $this->lastLink ) . $this->lastTagClose;
        }

        // Remove double slashes
        $output = preg_replace("#([^:])//+#", "\\1/", $output);

        // Add the wrapper HTML if exists
        $output = $this->fullTagOpen.$output.$this->fullTagClose;
        
        return $output;       
    }

    function getAJAXlink( $count, $text) {
        if($this->link_func == '' && $this->contentDiv == '')
            return '<a href="'.$this->baseURL.'?'.$count.'"'.$this->anchorClass.'>'.$text.'</a>';
        
        $pageCount = $count?$count:0;
        if(!empty($this->link_func)){
            $linkClick = 'onclick="'.$this->link_func.'('.$pageCount.')"';
        }else{
            $this->additionalParam = "{'page' : $pageCount}";
            $linkClick = "onclick=\"$.post('". $this->baseURL."', ". $this->additionalParam .", function(data){
                       $('#". $this->contentDiv . "').html(data); }); return false;\"";
        }
        
        return "<a href=\"javascript:void(0);\" " . $this->anchorClass . "
                ". $linkClick .">". $text .'</a>';
    }
}
?>
 

T4MAR4

Nuovo Utente
3 Lug 2017
10
0
1
39
index.php


Codice:
<!DOCTYPE HTML>
<html lang="en">
<head>


</head>
<body>




<div class="GET-search-panel">
    <input type="text" id="keyname" placeholder="name" onkeyup="searchFilter()"/>

    <input type="text" id="keywords" placeholder="Type keywords to filter GETs" onkeyup="searchFilter()"/>
    <select id="sortBy" onchange="searchFilter()">
        <option value="">Sort By</option>
        <option value="asc">Ascending</option>
        <option value="desc">Descending</option>
    </select>
</div>
<div class="GET-wrapper">
    <div id="GETs_content">
    <?php
    //Include pagination class file
    include('Pagination.php');
   
    //Include database configuration file
    include('dbConfig.php');
   
    $limit = 25;

    //get number of rows
    $queryNum = $db->query("SELECT COUNT(*) as xxxxxxx FROM ILFREE_core_members");
    $resultNum = $queryNum->fetch_assoc();
    $rowCount = $resultNum['xxxxxxx'];
   
    //initialize pagination class
    $pagConfig = array(
        'totalRows' => $rowCount,
        'perPage' => $limit,
        'link_func' => 'searchFilter'
    );
    $pagination =  new Pagination($pagConfig);
   
    //get rows
    $query = $db->query("SELECT * FROM ILFREE_core_members ORDER BY member_id DESC LIMIT $limit");
   
    if($query->num_rows > 0){ ?>
        <div class="GETs_list">

            
<?php         

while($row = $query->fetch_assoc()){
$GroupID = $row["member_group_id"];
$IDgroup = array('29','77','62','83','46','43','73','58','68','2','78','63','82','45','42','71','52','67','27','76','60','81','44','41','70','56','65');
$GETID = $row['member_id'];
$Name = $row["name"];
$photo = $row["pp_main_photo"];
$bannato = '7';


?>
<div class="list_item">
<?php
// name

echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '"  title="Visualizza il profilo di ' . $Name . '" ><h2>' . $Name . '</h2></a>';

// foto
if(empty($photo)) { if(in_array($GroupID, $IDgroup)) {
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/file/search_femmina.png"/></a>'; }
elseif ($bannato == $GroupID) {
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/file/ban.png"/></a>'; }
else {
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/file/search_maschio.png"/></a>'; } }
else{
echo '<a href="http://www.xxxx.it/index.php?/profile/' . $GETID . '-' . $Name . '" title="Visualizza il profilo di ' . $Name . '"><img src="http://www.xxxx.it/uploads/profile_photos/' . $photo . '"/></a>';
}








?>






   
          


            

            
            </div>                       
        <?php } ?>
        </div>   </div>
        <?php echo $pagination->createLinks(); ?>
    <?php } ?>

</div>

<style>

body {
    background: #e7e7e7 url(http://carpanelli-art.com/wp-content/themes/pacifico/images/bgs/bg_i_4.jpg) repeat;
    font-family: "FS Albert Light", "Myriad Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.GET-wrapper {
    padding: 10px;
    background: #fdfdfd;
    width: 70%;
    margin: 0 auto;
    border-radius: 6px;
}
.list_item {
    position: relative;
    float: left;
    border: 4px solid #f1f1f1;
    margin: 4px;
}
.list_item:hover {
       border: 4px solid #d6e9ff;

}
.list_item a {
    text-decoration: none;
    color: #b1b1b1;
   font-size: 10px;
    text-align: center;

}
.list_item a:hover {
       color: #8a8a8a;
}
.list_item img {
    width: 200px;
    height: 220px;
    display: list-item;
}

.list_item h2 {
    position: relative;
    margin: 0;
    background: #f4f5f9;
    border-bottom: 1px solid #f1f1f1;
    color: #3f4752;
    text-shadow: -1px -1px 0 #fff;
}
 #GETs_content {
    width: 70%;
        margin: 0 auto;
}
.GETs_list {display: inline-block;}
 div.pagination {
    font-family: "Lucida Sans", Geneva, Verdana, sans-serif;
    padding:20px;
    margin:7px;
    display: inline-block;
}
div.pagination a {
    margin: 2px;
    padding: 0.5em 0.64em 0.43em 0.64em;
    background-color: #ee4e4e;
    text-decoration: none;
    color: #fff;
}
div.pagination a:hover, div.pagination a:active {
    padding: 0.5em 0.64em 0.43em 0.64em;
    margin: 2px;
    background-color: #de1818;
    color: #fff;
}
div.pagination span.current {
    padding: 0.5em 0.64em 0.43em 0.64em;
    margin: 2px;
    background-color: #f6efcc;
    color: #6d643c;
}
div.pagination span.disabled {
    display:none;
}
</style>
            <!-- JavaScript -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script>
function searchFilter(page_num) {
    page_num = page_num?page_num:0;
    var keywords = $('#keywords').val();
    var keyname = $('#keyname').val();
    var sortBy = $('#sortBy').val();
    $.ajax({
        type: 'GET',
        url: 'getData.php',
        data:'page='+page_num+'&keyname='+keyname+'&keywords='+keywords+'&sortBy='+sortBy,
        beforeSend: function () {
            $('.loading-overlay').show();
        },
        success: function (html) {
            $('#GETs_content').html(html);
            $('.loading-overlay').fadeOut("slow");
        }
    });
}
</script>
</body>
</html>
Mi aiutate a capire come devo fare ?
le ho provate tutte ma non riesco ad andare avanti spero di essermi fatta capire al meg
lio, voglio creare un campo imput e questo campo maschio o femmina lavori insieme al campo di ricerca del nome, se uno scrive marco e clicca maschio mi dovrebbe far apparire tutti i maschi con il nome marco, escludendo le femmine, lo script è già impostato member_group_id è il codice che mi permette di farlo, infatti se creo un campo femmina o maschio mi scarica le femmine o i maschi, ma ripeto non lavora insieme al campo di ricerca utente..spero di essere stata chiara saluti