KoRnTuNeS February 2016

php - MySQL Pagination Filter Problems

I'm trying pagination and three filter on php - mysqli. MySQL query works on PhpMyAdmin, but not on php page. What is wrong?

<?php
include("header.php");

if(isset($_GET['numara'], $_GET['adsoyad'], $_GET['firmaadi']))
{
    $numaram=$_GET['numara'];     //numbers
    $adsoyad=$_GET['adsoyad'];    //FirstName and LastName
    $firmaadi=$_GET['firmaadi'];  //Company Name
}
    else
{
    $numaram="";
    $adsoyad="";
    $firmaadi="";
}

$sorgu = mysqli_query($mysqllink,"SELECT `id`, `numara`, `tarih`, `adsoyad`, `firmaadi` FROM `numaralar` WHERE (`numara` like '%$numaram%' or `adsoyad` like '%$adsoyad%' or `firmaadi` like '%$firmaadi%') order by `id`");

    if (isset($_GET["syf"]))
    {
        $syf=$_GET["syf"];
    }
    else
    {
        $syf=1;
    }

    $limit=3; 
    $kayitSayisi=mysqli_num_rows($sorgu);
    $sayfaSayisi=ceil($kayitSayisi/$limit);
    $baslangic=($syf*$limit)-$limit;

?>

<div id="divin">
<form method="GET" action="numaralistele2.php">
    Numara: <input type="textbox" name="numara"> Adı Soyadı: <input type="textbox" name="adsoyad"> Firma Adı: <input type="textbox" name="firmaadi"> <input type="submit" name="button" id="button" value="Arama Yap">
</form>
<?php
    $sorgu2=mysqli_query($mysqllink,"SELECT `id`, `numara`, `tarih`, `adsoyad`, `firmaadi` FROM `numaralar` WHERE (`numara` like '%$numaram%' or `adsoyad` like '%$adsoyad%' or `firmaadi` like '%$firmaadi%') order by `id` LIMIT $baslangic,$limit");
    echo "<table>";
    echo '<tr>
    <td>Silme</td><td>ID</td><td>NUMARA</td><td>TARİH</td><td>ADI SOYADI</td><td>FİRMA ADI</td>
    </tr>';
    while($kayit=mysqli_fetch_array($sorgu2)){
        echo '<tr>';
        echo '<td><a href="delete.php?id='.$kayit[0].'">Sil</a></td>';
        echo '<td>'.$kayit[0].'</td>';
        echo '<        

Answers


Atif Tariq February 2016

You have to write query like this:

$sorgu2=mysqli_query($mysqllink,"SELECT `id`, `numara`, `tarih`, `adsoyad`, `firmaadi` FROM `numaralar` WHERE (`numara` like '%$numaram%' AND `adsoyad` like '%$adsoyad%' AND `firmaadi` like '%$firmaadi%') order by `id` LIMIT $baslangic,$limit");


KoRnTuNeS February 2016

ok i finally solve my code. that work perfect, but not know "<>" that mean. Who know it? Why i must use "<>" in my codes?

<?php
include("header.php");

if(isset($_GET['numara']) || isset($_GET['adsoyad']) || isset($_GET['numara']))
{
    $ss[0]=$_GET['numara']<>''?" numara like '%".$_GET['numara']."%'" :""; //bunları bilmiyorum öğren...
    $ss[1]=$_GET['adsoyad']<>''?" adsoyad like '%".$_GET['adsoyad']."%'" :""; //bunları bilmiyorum öğren...
    $ss[2]=$_GET['firmaadi']<>''?" firmaadi like'%".$_GET['firmaadi']."%'" :""; //bunları bilmiyorum öğren...


    $numaram=$_GET['numara'];
    $adsoyad=$_GET['adsoyad'];
    $firmaadi=$_GET['firmaadi'];

    $ss=array_filter($ss);
    $sorgui=implode(" and ",$ss);  //dizilerin arasına and koydu

    $sorgui=count($ss)>0? "where $sorgui":"";
}
    else
{
    $sorgui="";
    $numaram="";
    $adsoyad="";
    $firmaadi="";
}



$sorgu = mysqli_query($mysqllink,"SELECT `id`, `numara`, `tarih`, `adsoyad`, `firmaadi` FROM `numaralar`  $sorgui order by `id`");

    if (isset($_GET["syf"]))
    {
        $syf=$_GET["syf"];
    }
    else
    {
        $syf=1;
    }

    $limit=3; 
    $kayitSayisi=mysqli_num_rows($sorgu);
    $sayfaSayisi=ceil($kayitSayisi/$limit);
    $baslangic=($syf*$limit)-$limit;
?>

<div id="divin">
<form method="GET" action="numaralistele2.php">
    Numara: <input type="textbox" name="numara"> Adı Soyadı: <input type="textbox" name="adsoyad"> Firma Adı: <input type="textbox" name="firmaadi"> <input type="submit" name="button" id="button" value="Arama Yap">
</form>
<?php
    $sorgu2=mysqli_query($mysqllink,"SELECT `id`, `numara`, `tarih`, `adsoyad`, `firmaadi` FROM `numaralar`  $sorgui order by `id` LIMIT $baslangic,$limit");
    echo "<table>";
    echo '<tr>
    <td>Silme</td><td>ID</td><td>NUMARA</td><td>TARİH</td><td>ADI SOYADI</ 

Post Status

Asked in February 2016
Viewed 1,652 times
Voted 6
Answered 2 times

Search




Leave an answer