I have written a form in with radio buttons the name is set to orderby and the value is set to KundeVorName and the next value is KundeNachName and it goes so on. I wanna modify my query according this values. It works well for the first page but at the second it looses its value and gives me an error message. When i hard code it like "Select * from Kunde ORDER BY KundeVorName" it works for all pages when i use my variable $orderby it works just for the first page. here is my code:
[code=php]
<html>
<head>
<style type="text/css">
A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {text-decoration: underline overline; color: red;}
table.second { margin-top:20px; margin-bottom:0px;}
</style>
<title>Implemen ting Paging with next and prev</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#99CC9 9">
<table width="60%" align="center" bgcolor="#00996 6"><tr>
<td><a href="insert.ph p">Veri Gir</a></td>
<td><a href="query.php ">Veri Görüntüle</a></td>
<td><a href="search.ph p"> Veri Ara </a></td>
<td><a href="update.ph p"> Veri Güncelle </a></td>
<td><a href="logout.ph p"> Ç?k?? </a></td>
</tr></table>
<?php
include 'connect.php';
$orderby = $_POST['orderby'];
$type = $_POST['type'];
if (isset($orderby )) {
echo "orderby is set\n";
} else {
echo "orderby is not set\n";
}
if (isset($type)) {
echo "type is set\n";
} else {
echo "type is not set\n";
}
// how many rows to show per page
$rowsPerPage = 5;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = " SELECT * FROM Kunde ORDER BY $orderby" .
" LIMIT $offset, $rowsPerPage";
$result = mysql_query($qu ery) or die('Error, query failed');
// start of the query *************** *************** *************** *************** *************** ****
?>
<div><table class='second' border='1'><tr> <td>ID</td><td>?sim Soyad</td><td>Firma</td><td>S?n?f</td><td>Ürünler</td><td>Adres</td><td>?ehir</td><td>Ülke</td><td>Türü</td><td>?? Telefonu</td><td>Fax</td><td>Cep</td><td>Mail</td><td>Web</td><td>Tarih</td></b></tr>
<?php
while($row = mysql_fetch_arr ay($result))
{
?>
<tr><td><?php echo $row['KundeID']; ?> </td>
<td> <?php echo $row['KundeVorName']." ".$r ow['KundeNachName']; ?> </td>
<td> <?php echo $row['KundeFirma']; ?> </td>
<td> <?php echo $row['KundeKategorie ']; ?> </td>
<td> <?php echo $row['KundeProdukte']; ?> </td>
<td> <?php echo $row['KundeAdresse']; ?> </td>
<td> <?php echo $row['KundeOrt']; ?> </td>
<td> <?php echo $row['KundeLand']; ?> </td>
<td> <?php echo $row['KundeArt']; ?> </td>
<td> <?php echo $row['KundeFestnetz']." "; ?> </td>
<td> <?php echo $row['KundeFax']." "; ?> </td>
<td> <?php echo $row['KundeMobile']." "; ?> </td>
<td> <?php $mail = $row['KundeMail']; ?><a href="mailto:<? php echo "$mail"; ?>"><?php echo $row['KundeMail']." "; ?> </a></td>
<td> <?php $web = $row['KundeWeb']; ?> <a href="http://<?php echo "$web"; ?>" Target="blank"> <?php echo $row['KundeWeb']." "; ?></a> </td>
<td> <?php echo $row['KundeRegDatum']." "; ?> </td></tr>
<?php } ?>
</table>
<?php
// end of the query *************** *************** *************** *************** *************** ****
// how many rows we have in database
$query = "SELECT COUNT(KundeID) AS numrows FROM Kunde ";
$result = mysql_query($qu ery) or die('Error, query failed');
$row = mysql_fetch_arr ay($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?pa ge=$page\">$pag e</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?pa ge=$page\">[Prev]</a> ";
$first = " <a href=\"$self?pa ge=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?pa ge=$page\">[Next]</a> ";
$last = " <a href=\"$self?pa ge=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
// and close the database connection
?>
</body>
</html>
[/code]
[Please use CODE tags when posting source code. Thanks! --pbmods]
I get orderby is not set ,type is not set and query error messages.
How can I fix my problem with the variables?
[code=php]
<html>
<head>
<style type="text/css">
A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {text-decoration: underline overline; color: red;}
table.second { margin-top:20px; margin-bottom:0px;}
</style>
<title>Implemen ting Paging with next and prev</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#99CC9 9">
<table width="60%" align="center" bgcolor="#00996 6"><tr>
<td><a href="insert.ph p">Veri Gir</a></td>
<td><a href="query.php ">Veri Görüntüle</a></td>
<td><a href="search.ph p"> Veri Ara </a></td>
<td><a href="update.ph p"> Veri Güncelle </a></td>
<td><a href="logout.ph p"> Ç?k?? </a></td>
</tr></table>
<?php
include 'connect.php';
$orderby = $_POST['orderby'];
$type = $_POST['type'];
if (isset($orderby )) {
echo "orderby is set\n";
} else {
echo "orderby is not set\n";
}
if (isset($type)) {
echo "type is set\n";
} else {
echo "type is not set\n";
}
// how many rows to show per page
$rowsPerPage = 5;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = " SELECT * FROM Kunde ORDER BY $orderby" .
" LIMIT $offset, $rowsPerPage";
$result = mysql_query($qu ery) or die('Error, query failed');
// start of the query *************** *************** *************** *************** *************** ****
?>
<div><table class='second' border='1'><tr> <td>ID</td><td>?sim Soyad</td><td>Firma</td><td>S?n?f</td><td>Ürünler</td><td>Adres</td><td>?ehir</td><td>Ülke</td><td>Türü</td><td>?? Telefonu</td><td>Fax</td><td>Cep</td><td>Mail</td><td>Web</td><td>Tarih</td></b></tr>
<?php
while($row = mysql_fetch_arr ay($result))
{
?>
<tr><td><?php echo $row['KundeID']; ?> </td>
<td> <?php echo $row['KundeVorName']." ".$r ow['KundeNachName']; ?> </td>
<td> <?php echo $row['KundeFirma']; ?> </td>
<td> <?php echo $row['KundeKategorie ']; ?> </td>
<td> <?php echo $row['KundeProdukte']; ?> </td>
<td> <?php echo $row['KundeAdresse']; ?> </td>
<td> <?php echo $row['KundeOrt']; ?> </td>
<td> <?php echo $row['KundeLand']; ?> </td>
<td> <?php echo $row['KundeArt']; ?> </td>
<td> <?php echo $row['KundeFestnetz']." "; ?> </td>
<td> <?php echo $row['KundeFax']." "; ?> </td>
<td> <?php echo $row['KundeMobile']." "; ?> </td>
<td> <?php $mail = $row['KundeMail']; ?><a href="mailto:<? php echo "$mail"; ?>"><?php echo $row['KundeMail']." "; ?> </a></td>
<td> <?php $web = $row['KundeWeb']; ?> <a href="http://<?php echo "$web"; ?>" Target="blank"> <?php echo $row['KundeWeb']." "; ?></a> </td>
<td> <?php echo $row['KundeRegDatum']." "; ?> </td></tr>
<?php } ?>
</table>
<?php
// end of the query *************** *************** *************** *************** *************** ****
// how many rows we have in database
$query = "SELECT COUNT(KundeID) AS numrows FROM Kunde ";
$result = mysql_query($qu ery) or die('Error, query failed');
$row = mysql_fetch_arr ay($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?pa ge=$page\">$pag e</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?pa ge=$page\">[Prev]</a> ";
$first = " <a href=\"$self?pa ge=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?pa ge=$page\">[Next]</a> ";
$last = " <a href=\"$self?pa ge=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
// and close the database connection
?>
</body>
</html>
[/code]
[Please use CODE tags when posting source code. Thanks! --pbmods]
I get orderby is not set ,type is not set and query error messages.
How can I fix my problem with the variables?
Comment