Tolongin ane donk.

gilang · Mar 8, 2013
stiap ane coba selalul salah. ada yang bisa bantu?
<?php
session_start();

$user = "root";
$pass = "";
$host = "localhost";
$db = "test";

$conn = mysql_connect($host,$user,$pass);
mysql_select_db($db);
if(!$conn){echo"Gagal Koneksi ke Database";}

if(isset($_POST)){
$_SESSION = $_POST;
}

$limitPaging = 5;

if($_SESSION != ""){
$sqlPaging = "SELECT COUNT(*) as TOTAL FROM nilai_s WHERE Nama like'%".$_SESSION."%'";
}else{
$sqlPaging = "SELECT COUNT(*) as TOTAL FROM nilai_s";
}
$resultPaging = mysql_query($sqlPaging);
$dataPaging = mysql_fetch_array($resultPaging);
$totalData = $dataPaging;
if($totalData > 0){
$totalPage = ceil($totalData/$limitPaging);
$page = $_GET;{

if($page == ""){
$offset = 0; $currentPage = 1;
}else{
$currentPage = $page; $offset = ($page-1)*$limitPaging;
}

$firstPage = 1;
$lastPage = $totalPage;
$nextPage = $currentPage+1;
$prevPage = $currentPage-1;
}
}
?>
<form action="?p=4&&page=1" method="post">
<fieldset>
<legend>Form Pencarian</legend>
<input type="text" name="kataKunci" />
<input name="search" type="submit" value="search" />
<b>Kata Kunci Anda : </b>"<?php echo $_SESSION; ?>"
</fieldset>
</form><br/><br/>
<?php
if($totalData > 0){
?>
<table align="center" width="100%">
<tr>
<th width="15%">&nbsp;</th>
<th width="15%">
<?php if($currentPage != 1){ ?>
<a href="<?php echo "?p=4&&page=$firstPage"; ?>"> &lt;&lt; Hal. Pertama </a>
<?php }?>
</th>
<th width="15%">
<?php if($currentPage != 1){ ?>
<a href="<?php echo "?p=4&&page=$prevPage"; ?>">&lt; Hal. Sebelumnya</a>
<?php }?>
</th>
<th> <?php echo"$currentPage/$totalPage " ?> </th>
<th width="15%">
<?php if($currentPage != $lastPage){ ?>
<a href="<?php echo "?p=4&&page=$nextPage"; ?>">Hal. Selanjutnya &gt;</a>
<?php }?>
</th>
<th width="15%">
<?php if($currentPage != $lastPage){ ?>
<a href="<?php echo "?p=4&&page=$lastPage"; ?>">Hal. Terakhir &gt; &gt; </a>
<?php }?>
</th>
<th width="15%">&nbsp;</th>
</tr>
</table><br/>
<?php
if($_SESSION != ""){
$sqlOrang = "SELECT * FROM nilai_s WHERE Nama LIKE '%".$_SESSION."%' LIMIT $offset,$limitPaging";
}else{
$sqlOrang = "SELECT * FROM nilai_s LIMIT $offset,$limitPaging";
}
$resultOrang = mysql_query($sqlOrang);
?>
<table class="bordered" >
<tr>
<th >No</th>
<th>Nama</th>
</tr>
<?php
$no = $offset+1;
while($dataOrang = mysql_fetch_array($resultOrang)){
echo"<tr>";
echo"<td>".$no."</td>";
echo"<td>".$dataOrang."</td>";
echo"</tr>";
$no++;
}
?>
</table>
<?php
}else{
echo"Data dengan Kata Kunci : <b>'".$_SESSION."'</b> Tidak Ditemukan !!!";
}
?>
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Mar 8, 2013 · 0 Suka · 0 Tidak Suka
intinya adalah method form yang digunakan, jika ingin search dengan pagination, maka method form harus get bukan post.
<?php
session_start();

$user = "root";
$pass = "";
$host = "localhost";
$db = "test";

$conn = mysql_connect($host, $user, $pass);
mysql_select_db($db);
if (!$conn) {
    echo"Gagal Koneksi ke Database";
}
$kataKunci = '';
if (isset($_GET['kataKunci'])) {
    $kataKunci = $_GET['kataKunci'];
}

$limitPaging = 5;

if ($kataKunci != "") {
    $sqlPaging = "SELECT COUNT(*) as TOTAL FROM nilai_s WHERE Nama like'%" . $kataKunci . "%'";
} else {
    $sqlPaging = "SELECT COUNT(*) as TOTAL FROM nilai_s";
}
$resultPaging = mysql_query($sqlPaging);
$dataPaging = mysql_fetch_array($resultPaging);
$totalData = $dataPaging['TOTAL'];
if ($totalData > 0) {
    $totalPage = ceil($totalData / $limitPaging);
    $page = $_GET['page'];
    {

        if ($page == "") {
            $offset = 0;
            $currentPage = 1;
        } else {
            $currentPage = $page;
            $offset = ($page - 1) * $limitPaging;
        }

        $firstPage = 1;
        $lastPage = $totalPage;
        $nextPage = $currentPage + 1;
        $prevPage = $currentPage - 1;
    }
}
?>
<form action="?p=4&&page=1" method="get">
    <fieldset>
        <legend>Form Pencarian</legend>
        <input type="text" name="kataKunci" />
        <input type="hidden" name="p" value="4"/>
        <input type="hidden" name="page" value="1"/>
        <input name="search" type="submit" value="search" />
        <b>Kata Kunci Anda : </b>"<?php echo $kataKunci; ?>"
    </fieldset>
</form><br/><br/>
<?php
if ($totalData > 0) {
    ?>
    <table align="center" width="100%">
        <tr>
            <th width="15%">&nbsp;</th>
            <th width="15%">
                <?php if ($currentPage != 1) { ?>
                    <a href="<?php echo "?p=4&&page={$firstPage}&kataKunci={$kataKunci}"; ?>"> &lt;&lt; Hal. Pertama </a>
                <?php } ?>
            </th>
            <th width="15%">
                <?php if ($currentPage != 1) { ?>
                    <a href="<?php echo "?p=4&&page={$prevPage}&kataKunci={$kataKunc}i"; ?>">&lt; Hal. Sebelumnya</a>
                <?php } ?>
            </th>
            <th> <?php echo"$currentPage/$totalPage " ?> </th>
            <th width="15%">
                <?php if ($currentPage != $lastPage) { ?>
                    <a href="<?php echo "?p=4&&page={$nextPage}&kataKunci={$kataKunci}"; ?>">Hal. Selanjutnya &gt;</a>
                <?php } ?>
            </th>
            <th width="15%">
    <?php if ($currentPage != $lastPage) { ?>
                    <a href="<?php echo "?p=4&&page={$lastPage}&kataKunci={$kataKunci}"; ?>">Hal. Terakhir &gt; &gt; </a>
    <?php } ?>
            </th>
            <th width="15%">&nbsp;</th>
        </tr>
    </table><br/>
    <?php
    if ($kataKunci != "") {
        $sqlOrang = "SELECT * FROM nilai_s WHERE Nama LIKE '%" . $kataKunci . "%' LIMIT $offset,$limitPaging";
    } else {
        $sqlOrang = "SELECT * FROM nilai_s LIMIT $offset,$limitPaging";
    }
    $resultOrang = mysql_query($sqlOrang);
    ?>
    <table class="bordered" >
        <tr>
            <th >No</th>
            <th>Nama</th>
        </tr>
        <?php
        $no = $offset + 1;
        while ($dataOrang = mysql_fetch_array($resultOrang)) {
            echo"<tr>";
            echo"<td>" . $no . "</td>";
            echo"<td>" . $dataOrang['Nama'] . "</td>";
            echo"</tr>";
            $no++;
        }
        ?>
    </table>
    <?php
} else {
    echo"Data dengan Kata Kunci : <b>'" . $kataKunci . "'</b> Tidak Ditemukan !!!";
}
?>
0
Loading...
gilang · Mar 8, 2013 · 0 Suka · 0 Tidak Suka
Sma Aja gan hasilnya dengan code yang di atas dimana letak kesalahanya di awal ketika masuk ke phpnya. setelah dklik pencarian atau tabel sleanjutnya errornya hilang. dan error itu terjadi pada
Notice: Undefined index: page in C:\Program Files\wamp\www\Test\search pagnition.php on line 31
error ini akan terus ada jika kita ke home dari alamat phpnya sendiri.
tolongin yhaa gan. please:(
0
Loading...
Ellyx Christian · Mar 8, 2013 · 0 Suka · 0 Tidak Suka
tinggal ganti
$page = $_GET
jadi
$page = isset($_GET) ? $_GET : '';
0
Loading...
gilang · Mar 8, 2013 · 0 Suka · 0 Tidak Suka
thanks gan. berhasil:). agar ditengah2nya ada nomor 1 2 3 jika tabelnya tesedia selain nex prev last first bisa gak gan?
lw gak d bantupun gak ppa gan. maaf udah ganggu yaa
0
Loading...
Ellyx Christian · Mar 9, 2013 · 0 Suka · 0 Tidak Suka
<table align="center" width="100%">
        <tr>
            <th width="15%">&nbsp;</th>
            <th width="15%">
                <?php if ($currentPage != 1) { ?>
                    <a href="<?php echo "?p=4&&page={$firstPage}&kataKunci={$kataKunci}"; ?>"> &lt;&lt; Hal. Pertama </a>
                <?php } ?>
            </th>
            <th width="15%">
                <?php if ($currentPage != 1) { ?>
                    <a href="<?php echo "?p=4&&page={$prevPage}&kataKunci={$kataKunci}"; ?>">&lt; Hal. Sebelumnya</a>
                <?php } ?>
            </th>
            <?php
            for($i = 1; $i <= $totalPage; $i++){?>
            <th>
            	<?php if($i == $currentPage){
            	echo $i;
		}else{?>
		<a href="<?php echo "?p=4&&page={$i}&kataKunci={$kataKunc}"; ?>"><?php echo $i?></a>
		<?php }?>
            </th>
            <?php
            }
            ?>
            <th width="15%">
                <?php if ($currentPage != $lastPage) { ?>
                    <a href="<?php echo "?p=4&&page={$nextPage}&kataKunci={$kataKunci}"; ?>">Hal. Selanjutnya &gt;</a>
                <?php } ?>
            </th>
            <th width="15%">
    <?php if ($currentPage != $lastPage) { ?>
                    <a href="<?php echo "?p=4&&page={$lastPage}&kataKunci={$kataKunci}"; ?>">Hal. Terakhir &gt; &gt; </a>
    <?php } ?>
            </th>
            <th width="15%">&nbsp;</th>
        </tr>
    </table>
tutorial pagination http://www.myphptutorials.com/tutorials/31/membuat-pagination
0
Loading...
gilang · Mar 9, 2013 · 0 Suka · 0 Tidak Suka
Berhasilgan,thanks tetpi jika ada lbih dari 10. kok nomornya kluar semua. bsakah sperti pagnition web agan? contoh: first prev 7 8 9 next last. jika di klik 9 mka, first prev 8 9 10 next last.
0
Loading...
Ellyx Christian · Mar 9, 2013 · 0 Suka · 0 Tidak Suka
0
Loading...
gilang · Mar 9, 2013 · 0 Suka · 0 Tidak Suka
tlong implementasikan ke code ane gan dri tadi salah mulu:(
0
Loading...
Ellyx Christian · Mar 10, 2013 · 0 Suka · 0 Tidak Suka
pertama bikin file digg.php
<?php
//file digg.php
//function to return the pagination string
function getPaginationString($page = 1, $totalitems, $limit = 15, $targetpage = "/", $pagestring = "?page=")
{		
	//defaults
	$adjacents = 1;
	if(!$limit) $limit = 15;
	if(!$page) $page = 1;
	if(!$targetpage) $targetpage = "/";
	
	//other vars
	$prev = $page - 1;									//previous page is page - 1
	$next = $page + 1;									//next page is page + 1
	$lastpage = ceil($totalitems / $limit);				//lastpage is = total items / items per page, rounded up.
	$lpm1 = $lastpage - 1;								//last page minus 1
	
	/* 
		Now we apply our rules and draw the pagination object. 
		We're actually saving the code to a variable in case we want to draw it more than once.
	*/
	$pagination = "";
	if($lastpage > 1)
	{	
		$pagination .= "<div class=\"pagination\"";
		if($margin || $padding)
		{
			$pagination .= " style=\"";
			if($margin)
				$pagination .= "margin: $margin;";
			if($padding)
				$pagination .= "padding: $padding;";
			$pagination .= "\"";
		}
		$pagination .= ">";

		//previous button
		if ($page > 1) 
			$pagination .= "<a href=\"$targetpage$pagestring$prev\">« prev</a>";
		else
			$pagination .= "<span class=\"disabled\">« prev</span>";	
		
		//pages	
		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination .= "<span class=\"current\">$counter</span>";
				else
					$pagination .= "<a href=\"" . $targetpage . $pagestring . $counter . "\">$counter</a>";					
			}
		}
		elseif($lastpage >= 7 + ($adjacents * 2))	//enough pages to hide some
		{
			//close to beginning; only hide later pages
			if($page < 1 + ($adjacents * 3))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						$pagination .= "<span class=\"current\">$counter</span>";
					else
						$pagination .= "<a href=\"" . $targetpage . $pagestring . $counter . "\">$counter</a>";					
				}
				$pagination .= "<span class=\"elipses\">...</span>";
				$pagination .= "<a href=\"" . $targetpage . $pagestring . $lpm1 . "\">$lpm1</a>";
				$pagination .= "<a href=\"" . $targetpage . $pagestring . $lastpage . "\">$lastpage</a>";		
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				$pagination .= "<a href=\"" . $targetpage . $pagestring . "1\">1</a>";
				$pagination .= "<a href=\"" . $targetpage . $pagestring . "2\">2</a>";
				$pagination .= "<span class=\"elipses\">...</span>";
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
						$pagination .= "<span class=\"current\">$counter</span>";
					else
						$pagination .= "<a href=\"" . $targetpage . $pagestring . $counter . "\">$counter</a>";					
				}
				$pagination .= "...";
				$pagination .= "<a href=\"" . $targetpage . $pagestring . $lpm1 . "\">$lpm1</a>";
				$pagination .= "<a href=\"" . $targetpage . $pagestring . $lastpage . "\">$lastpage</a>";		
			}
			//close to end; only hide early pages
			else
			{
				$pagination .= "<a href=\"" . $targetpage . $pagestring . "1\">1</a>";
				$pagination .= "<a href=\"" . $targetpage . $pagestring . "2\">2</a>";
				$pagination .= "<span class=\"elipses\">...</span>";
				for ($counter = $lastpage - (1 + ($adjacents * 3)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
						$pagination .= "<span class=\"current\">$counter</span>";
					else
						$pagination .= "<a href=\"" . $targetpage . $pagestring . $counter . "\">$counter</a>";					
				}
			}
		}
		
		//next button
		if ($page < $counter - 1) 
			$pagination .= "<a href=\"" . $targetpage . $pagestring . $next . "\">next »</a>";
		else
			$pagination .= "<span class=\"disabled\">next »</span>";
		$pagination .= "</div>\n";
	}
	
	return $pagination;

}
kemudian untuk buat paging
include_once 'digg.php';
echo getPaginationString($currentPage, $totalData, $limitPaging, "?p=4&kataKunci={$kataKunci}", "&page=");
0
Loading...
gilang · Mar 11, 2013 · 0 Suka · 0 Tidak Suka
Berhasil gan.
Thanks..
:)