Alex Piotto
08-28-2002, 02:57 PM
That's it.... still can't get the links at the bottom of the page to work.....!!!!!!!!!!!!!!!!
Everything works in the below code, but the link to next page.
it seems that when I click the next page link the page just reloads
here is the complete code:
___________________________
<?
//if ($file = ($wichdb)){
if ($file){$file = ($wichdb);}
else {$file = "Catalogo-1.txt";}
$searchPattern = ''; // contains the searchPattern
function search_csv($file, $searchString){
if (empty($searchString)) {return false;} // check if the search string contains nothing
global $searchPattern; $results = array(); // Declare global variables
$keywords = preg_split('/[\s]+/', trim($searchString)); // prepare search pattern
$keywords = array_values(array_unique($keywords)); // remove duplicate entries
for ($k = 0; $k < count($keywords); $k++) {
$keywords[$k] = '\b' . preg_quote($keywords[$k], '/') . '\b';} // escape preg specific characters and find only complete keywords
$searchPattern = '/(' . implode('|', $keywords) . ')/i'; // build the search case-insensitive pattern
$fp = fopen($file, "r"); // go through the file
while ( ($str = fread($fp, 1)) != "\n" ) {} // advance the file pointer to the next line
while ($fields = fgetcsv ($fp, 4096, ";")) { // iterate through each line and
if (preg_match ($searchPattern, $fields[0] . ' ' . $fields[1]. ' ' . $fields[2]. ' ' . $fields[3]. ' ' . $fields[4]. ' ' . $fields[5])) {
$results[] = $fields; // search all the fields
}
}
fclose ($fp);
return $results;
}
// Show the input form
if ($file){
echo "<html><body style='font-family:verdana;font size:12px;'>";
echo "<form method='post' action='$PHP_SELF'>";
echo "<input type='hidden' name='submitted' value='done'>";
echo "<input type='hidden' name='filename' value='$file'>";
echo "<b>Procurar por:</b> <input type='text' name='keyword' size='58'>";
echo "<input type='submit' value='Buscar' name='submit'></form>";
}
// call the function if form has been submitted
if (($submitted) && ($submitted = 'done')) {
$file = ($filename);
$results = search_csv($file, $keyword);
echo "<div style='font-family:verdana; font-size:12px; color:#000000;'>\n";
if (!$results || count($results) == 0) { echo "<font color='blue'><b>Não encontrei nada...</b></font>\n";}
else { echo "<font color='blue'><b>Resultados da Busca:</b></font><br /><br />\n";
// Do some calculations
$numrows = count($results);
if (!($limit)){$limit = 10;}
if (!($page)){$page = 0;}
$pages = intval($numrows/$limit);
if ($numrows%$limit) { $pages++;}
$current = ($page/$limit) + 1;
if (($pages < 1) || ($pages == 0)) { $total = 1;}
else {$total = $pages;}
$first = $page + 1;
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {$last = $page + $limit;}
else{$last = $numrows;}
// Write down how many items in the results, how many pages etc.
echo "<html><head><style>A:hover {color: #FF0000; font-size: 13 px; font-family: Verdana;}</style></head>";
echo "<body link='#0000FF' vlink='#0000FF' alink='#0000FF'><table style='font-family:verdana; font-size:13px;' width='100%' border='0' cellspacing='0'><tr>";
echo "<td style='border-top: 1 solid #0000FF; border-bottom: 1 solid #0000FF' width='50%' align='left'>Items <b>$first</b> - <b>$last</b> de <b>$numrows</b><br></td>";
echo "<td style='border-top: 1 solid #0000FF; border-bottom: 1 solid #0000FF' width='50%' align='right'>Página <b>$current</b> de <b>$total</b><br></td></tr></table><br>";
// Write down paged search results (at list the first ten... sigh!)
$items_per_page = 10;
if ($linkpage == '' or !$linkpage) { $linkpage = 1; }
$end = $items_per_page * $linkpage;
$start = $end - $items_per_page;
if ($start<>'0') { $new_page=$linkpage-1;
$prev="<a href='searchTEST.php?linkpage=$new_page'>Previous page</a>";} else {$prev="";}
if ($end<$numrows) { $new_page1=$linkpage+1;
$next="<a href='searchTEST.php?linkpage=$new_page1'>Next page</a>";} else {$next="";}
for ($i=$start; $i<$end; $i++) {
echo "<b>ID: </b>" . $results[$i][0] . "<br />";
echo "<b>Bairro: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][1]) . "<br />";
echo "<b>Genero: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][2]) . "<br />";
echo "<b>Tipo: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][3]) . "<br />";
echo "<b>USD/Mês: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][4]) . "<br />";
echo "<b>Descrição: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][5]) . "<br /><hr>\n";
}
echo "</div>";
} // close the "else" of the call to function search_csv
} // close the call to the function search_csv
?>
</body>
</html>
______________________________
Please, I am going mad on it... Why this is happening?
Is a problem of storage, as murdred said, or ? I checked the linkpage value, and it is send when click the link....
Help!!!!!!!!
:confused: :confused: :confused: :confused: :confused: :confused:
Alex:(
Everything works in the below code, but the link to next page.
it seems that when I click the next page link the page just reloads
here is the complete code:
___________________________
<?
//if ($file = ($wichdb)){
if ($file){$file = ($wichdb);}
else {$file = "Catalogo-1.txt";}
$searchPattern = ''; // contains the searchPattern
function search_csv($file, $searchString){
if (empty($searchString)) {return false;} // check if the search string contains nothing
global $searchPattern; $results = array(); // Declare global variables
$keywords = preg_split('/[\s]+/', trim($searchString)); // prepare search pattern
$keywords = array_values(array_unique($keywords)); // remove duplicate entries
for ($k = 0; $k < count($keywords); $k++) {
$keywords[$k] = '\b' . preg_quote($keywords[$k], '/') . '\b';} // escape preg specific characters and find only complete keywords
$searchPattern = '/(' . implode('|', $keywords) . ')/i'; // build the search case-insensitive pattern
$fp = fopen($file, "r"); // go through the file
while ( ($str = fread($fp, 1)) != "\n" ) {} // advance the file pointer to the next line
while ($fields = fgetcsv ($fp, 4096, ";")) { // iterate through each line and
if (preg_match ($searchPattern, $fields[0] . ' ' . $fields[1]. ' ' . $fields[2]. ' ' . $fields[3]. ' ' . $fields[4]. ' ' . $fields[5])) {
$results[] = $fields; // search all the fields
}
}
fclose ($fp);
return $results;
}
// Show the input form
if ($file){
echo "<html><body style='font-family:verdana;font size:12px;'>";
echo "<form method='post' action='$PHP_SELF'>";
echo "<input type='hidden' name='submitted' value='done'>";
echo "<input type='hidden' name='filename' value='$file'>";
echo "<b>Procurar por:</b> <input type='text' name='keyword' size='58'>";
echo "<input type='submit' value='Buscar' name='submit'></form>";
}
// call the function if form has been submitted
if (($submitted) && ($submitted = 'done')) {
$file = ($filename);
$results = search_csv($file, $keyword);
echo "<div style='font-family:verdana; font-size:12px; color:#000000;'>\n";
if (!$results || count($results) == 0) { echo "<font color='blue'><b>Não encontrei nada...</b></font>\n";}
else { echo "<font color='blue'><b>Resultados da Busca:</b></font><br /><br />\n";
// Do some calculations
$numrows = count($results);
if (!($limit)){$limit = 10;}
if (!($page)){$page = 0;}
$pages = intval($numrows/$limit);
if ($numrows%$limit) { $pages++;}
$current = ($page/$limit) + 1;
if (($pages < 1) || ($pages == 0)) { $total = 1;}
else {$total = $pages;}
$first = $page + 1;
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {$last = $page + $limit;}
else{$last = $numrows;}
// Write down how many items in the results, how many pages etc.
echo "<html><head><style>A:hover {color: #FF0000; font-size: 13 px; font-family: Verdana;}</style></head>";
echo "<body link='#0000FF' vlink='#0000FF' alink='#0000FF'><table style='font-family:verdana; font-size:13px;' width='100%' border='0' cellspacing='0'><tr>";
echo "<td style='border-top: 1 solid #0000FF; border-bottom: 1 solid #0000FF' width='50%' align='left'>Items <b>$first</b> - <b>$last</b> de <b>$numrows</b><br></td>";
echo "<td style='border-top: 1 solid #0000FF; border-bottom: 1 solid #0000FF' width='50%' align='right'>Página <b>$current</b> de <b>$total</b><br></td></tr></table><br>";
// Write down paged search results (at list the first ten... sigh!)
$items_per_page = 10;
if ($linkpage == '' or !$linkpage) { $linkpage = 1; }
$end = $items_per_page * $linkpage;
$start = $end - $items_per_page;
if ($start<>'0') { $new_page=$linkpage-1;
$prev="<a href='searchTEST.php?linkpage=$new_page'>Previous page</a>";} else {$prev="";}
if ($end<$numrows) { $new_page1=$linkpage+1;
$next="<a href='searchTEST.php?linkpage=$new_page1'>Next page</a>";} else {$next="";}
for ($i=$start; $i<$end; $i++) {
echo "<b>ID: </b>" . $results[$i][0] . "<br />";
echo "<b>Bairro: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][1]) . "<br />";
echo "<b>Genero: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][2]) . "<br />";
echo "<b>Tipo: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][3]) . "<br />";
echo "<b>USD/Mês: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][4]) . "<br />";
echo "<b>Descrição: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][5]) . "<br /><hr>\n";
}
echo "</div>";
} // close the "else" of the call to function search_csv
} // close the call to the function search_csv
?>
</body>
</html>
______________________________
Please, I am going mad on it... Why this is happening?
Is a problem of storage, as murdred said, or ? I checked the linkpage value, and it is send when click the link....
Help!!!!!!!!
:confused: :confused: :confused: :confused: :confused: :confused:
Alex:(