prislea
05-30-2008, 01:39 PM
Hi,
I've made a php page for vbadvanced, it is a dictionary and the code look like this:
<?php
error_reporting(E_ALL & ~E_NOTICE);
define ('NO_REGISTER_GLOBALS', 1);
define ('THIS_SCRIPT', 'dictionar');
require_once('./global.php');
$rowsPerPage = 30;
$pageNum = 1;
$inx = 0;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
echo "<tr><td class=\"alt2\">"
."<div align=\"center\">"
."<form action=\"index.php?pageid=dictionar\" method=\"post\">"
.$vbphrase['dic_find'].":"
."<input type=\"text\" name=\"dicSearch\" size=\"26\">"
."<select name=\"searchType\">"
."<option selected value=\"exact\">".$vbphrase['dic_exact']."</option>"
."<option value=\"starts_with\">".$vbphrase['dic_starts']."</option>"
."<option value=\"ends_with\">".$vbphrase['dic_ends']."</option>"
."<option value=\"contains\">".$vbphrase['dic_contains']."</option>"
."</select>"
."<input type=Submit value=\"".$vbphrase['dic_search']."\">"
."</form>"
."</div>"
."<br />";
$dicSearch = $_POST['dicSearch'];
$searchType = $_POST['searchType'];
$searchTypeText = "='$dicSearch'";
if($searchType == "starts_with") {
$searchTypeText = " like '$dicSearch%'";
}
else if($searchType == "ends_with") {
$searchTypeText = " like '%$dicSearch'";
}
else if($searchType == "contains") {
$searchTypeText = " like '%$dicSearch%'";
}
if($dicSearch != "") {
$resultat = $db->query_read("SELECT * FROM " . TABLE_PREFIX ."dictionar_dictionary WHERE dic_word".$searchTypeText." order by dic_word LIMIT $offset, $rowsPerPage");
while(list($did, $dic_word, $dic_def) = $db->fetch_row($resultat)) {
echo "<br><strong>$dic_word</strong> <i>$dic_def</i><br>";
$inx++;
}
if($inx == 0) {
echo "<center><strong><i>$dicSearch</i> ".$vbphrase['dic_notfound']."</strong></center>";
}
echo "<br><center>";
$resultat = $db->query_read("SELECT COUNT(*) AS numrows FROM " . TABLE_PREFIX ."dictionar_dictionary WHERE dic_word".$searchTypeText);
$row = $db->fetch_array($resultat, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if($page == $pageNum)
{
$nav .= " $page ";
}
else
{
$nav .= " <a href=\"$self?pageid=dictionar&page=$page\">$page</a> ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?pageid=dictionar&page=$page\">[".$vbphrase['dic_previous']."]</a> ";
$first = " <a href=\"$self?pageid=dictionar&page=1\">[".$vbphrase['dic_first']."]</a> ";
}
else
{
$prev = ' ';
$first= ' ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?pageid=dictionar&page=$page\">[".$vbphrase['dic_next']."]</a> ";
$last = " <a href=\"$self?pageid=dictionar&page=$maxPage\">[".$vbphrase['dic_last']."]</a> ";
}
else
{
$next = ' ';
$last= ' ';
}
echo $first . $prev . $nav . $next . $last;
echo "</center>";
echo "<BR>";
}
$totaldb = $db->num_rows($db->query_read("SELECT * FROM " . TABLE_PREFIX . "dictionar_dictionary"));
echo "<div align=\"right\"><FONT class=\"smallfont\" color=\"red\">".$vbphrase['dic_totaldb'].": $totaldb ".$vbphrase['dic_words']."</FONT></div>\n";
echo "</td></tr>";
?>
everything is working fine until I need to go to the next page. I am a beginner in php and programing in general and I dont know what the problem is.
when I click on the [next] link what looks like this
http://www.mysite.net/index.php?pageid=dictionar&page=2
I get the page without results like the begin page.
I've made a php page for vbadvanced, it is a dictionary and the code look like this:
<?php
error_reporting(E_ALL & ~E_NOTICE);
define ('NO_REGISTER_GLOBALS', 1);
define ('THIS_SCRIPT', 'dictionar');
require_once('./global.php');
$rowsPerPage = 30;
$pageNum = 1;
$inx = 0;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
echo "<tr><td class=\"alt2\">"
."<div align=\"center\">"
."<form action=\"index.php?pageid=dictionar\" method=\"post\">"
.$vbphrase['dic_find'].":"
."<input type=\"text\" name=\"dicSearch\" size=\"26\">"
."<select name=\"searchType\">"
."<option selected value=\"exact\">".$vbphrase['dic_exact']."</option>"
."<option value=\"starts_with\">".$vbphrase['dic_starts']."</option>"
."<option value=\"ends_with\">".$vbphrase['dic_ends']."</option>"
."<option value=\"contains\">".$vbphrase['dic_contains']."</option>"
."</select>"
."<input type=Submit value=\"".$vbphrase['dic_search']."\">"
."</form>"
."</div>"
."<br />";
$dicSearch = $_POST['dicSearch'];
$searchType = $_POST['searchType'];
$searchTypeText = "='$dicSearch'";
if($searchType == "starts_with") {
$searchTypeText = " like '$dicSearch%'";
}
else if($searchType == "ends_with") {
$searchTypeText = " like '%$dicSearch'";
}
else if($searchType == "contains") {
$searchTypeText = " like '%$dicSearch%'";
}
if($dicSearch != "") {
$resultat = $db->query_read("SELECT * FROM " . TABLE_PREFIX ."dictionar_dictionary WHERE dic_word".$searchTypeText." order by dic_word LIMIT $offset, $rowsPerPage");
while(list($did, $dic_word, $dic_def) = $db->fetch_row($resultat)) {
echo "<br><strong>$dic_word</strong> <i>$dic_def</i><br>";
$inx++;
}
if($inx == 0) {
echo "<center><strong><i>$dicSearch</i> ".$vbphrase['dic_notfound']."</strong></center>";
}
echo "<br><center>";
$resultat = $db->query_read("SELECT COUNT(*) AS numrows FROM " . TABLE_PREFIX ."dictionar_dictionary WHERE dic_word".$searchTypeText);
$row = $db->fetch_array($resultat, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if($page == $pageNum)
{
$nav .= " $page ";
}
else
{
$nav .= " <a href=\"$self?pageid=dictionar&page=$page\">$page</a> ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?pageid=dictionar&page=$page\">[".$vbphrase['dic_previous']."]</a> ";
$first = " <a href=\"$self?pageid=dictionar&page=1\">[".$vbphrase['dic_first']."]</a> ";
}
else
{
$prev = ' ';
$first= ' ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?pageid=dictionar&page=$page\">[".$vbphrase['dic_next']."]</a> ";
$last = " <a href=\"$self?pageid=dictionar&page=$maxPage\">[".$vbphrase['dic_last']."]</a> ";
}
else
{
$next = ' ';
$last= ' ';
}
echo $first . $prev . $nav . $next . $last;
echo "</center>";
echo "<BR>";
}
$totaldb = $db->num_rows($db->query_read("SELECT * FROM " . TABLE_PREFIX . "dictionar_dictionary"));
echo "<div align=\"right\"><FONT class=\"smallfont\" color=\"red\">".$vbphrase['dic_totaldb'].": $totaldb ".$vbphrase['dic_words']."</FONT></div>\n";
echo "</td></tr>";
?>
everything is working fine until I need to go to the next page. I am a beginner in php and programing in general and I dont know what the problem is.
when I click on the [next] link what looks like this
http://www.mysite.net/index.php?pageid=dictionar&page=2
I get the page without results like the begin page.