Please help with nuke module...simple search script...

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   Please help with nuke module...simple search script...
Gunner
CZ Newbie
Gunner has been a member for over 20 year's 20 Year Member
Occupation: Medical Student
Website:
Status: Offline
Joined: Mar 16, 2004
0.00 posts per day
Posts: 1
Points: 200
   
I'm stuck! below is the code from a simple search script that searches a table called nuke_beer (it contains beer reviews from my site). The script works except for a single component. The problem is...when there are more than one page of results and the option to retrieve the "next" page is selected, the following meassge appears "Sorry, you can't access this file directly..." To see the error in action search for the word "ale" then hover the mouse over the "next" hyperlink...you can see the url is not in proper nuke format. It is a problem with this line..I think:

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " ;;<a href=\"$PHP_SELF?s=$prevs&q=$varsearch\">&lt;&lt;
  Prev 10</a> ; ;;";
  }



The link to the module is here: [ Register or login to view links on this board. ]

I'm new to coding (I'm learning php and mysql from a book I bought) any help greatly appreciated...I know this is a long post icon_rolleyes.gif tnx


The entire code
<?php
//nuke specific stuff
if (!eregi("modules.php", $PHP_SELF)){
  die ("You can't access this rows directly...");
}
$index = 1;
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");



//search function form code
echo "<table align='center' border='0' cellspacing='0' cellpadding='2'>";
echo "<tr>";
echo "<td><form name='form' method='POST' action=''>";
echo "<div align='center'><strong>Search Fragment:</strong>";
echo "<input name='q' type='text' size='35'>";
echo "<input name='Submit' type='submit' value='Go'>";
echo "<span class='style2'>*single word searching only </span>";
echo "</div>";
echo "</form></td>";
echo "</tr>";
echo "</table>";


//start search script code
// Get the search variable 'q' from the html form
$varsearch = @$_POST['q'] ;
$trimmed = trim($varsearch); //trim whitespace from the stored variable
 
// check for an empty string and display a message.
if ($trimmed == "")
{
//echo "<p>Please enter a beer name to search...</p>";
exit;
}

// check for a search parameter
if (!isset($varsearch))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}

// Build SQL Query 
$querystr = "select bn, url, fi, speed, cool, tq, os, poster FROM ".$prefix. "_beer where bn like \"%$trimmed%\" order by bn"; 
$numresultssearch=sql_query($querystr, $dbi);
$numrowssearch=sql_num_rows($numresultssearch, dbi);

// Number of rows to return
$limit=10;

//If no results conditional
if ($numrowssearch == 0)
  {
 
  echo "<h4>Results:</h4>";
  echo "Sorry, your search: <i><b>\"$trimmed\"</i></b> returned zero results. Try again using smaller <i><b>\"search fragments.\"</b></i> For example, <b>\"budweiser\"</b> should be input as <b>\"bud\"</b> ;;";
  echo 'Please try again.';
  echo '<br></br>';
   }

//Determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
  }
 
//Get results
$querystr .= " limit $s, $limit";
$resultsearch = sql_query($querystr, $dbi) or die("Couldn't execute query");

//Begin to show results set
$count = 1 + $s ;
 
//Add my block result code
if ($numrowssearch) { echo
'<table align="center" cellspacing="0" cellpadding="2" table border="1">
<td align="left"><b><a>Beer name</b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "First Impression: What are your initial thoughts on colour, aroma, head, taste, etc...">First Impression</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Speed: Can you drink this beer in vast quantities and with speed? Or is it more of a sipper? AKA: the “Poundability Factor.”">Speed</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Intangibity: Other than the taste, are there things about the label, advertising, etc... that make you appreciate this brew?">Intangibility</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Taste Quality: Now that you’re well into the beer, what do you think about how it tastes?">Taste Quality</a></b></td>
<td align="left"><b><a href= "http://www.boozebros.ca/postt7.html" title = "Overall Score: Just math. Add’em up.">Overall Score</a></b></td>
<td align="left"><b>Poster</b></td></tr>
<strong>Your Search Results:</strong>';

//Now you can display the results returned
while ($rowsearch = sql_fetch_array($resultsearch, $dbi))

{echo
"<tr><td align=\"left\"><a href='$rowsearch[1]'>$rowsearch[0]</a></td>
<td align=\"left\">$rowsearch[2]</td>
<td align=\"left\">$rowsearch[3]</td>
<td align=\"left\">$rowsearch[4]</td>
<td align=\"left\">$rowsearch[5]</td>
<td align=\"left\">$rowsearch[6]</td>
<td align=\"left\">$rowsearch[7]</td></tr>"; }

echo '</table>';

}

//Page code
$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " ;;<a href=\"$PHP_SELF?s=$prevs&q=$varsearch\">&lt;&lt;
  Prev 10</a> ; ;;";
  }

// calculate number of pages needing links
  $pages=intval($numrowssearch/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrowssearch%$limit) {
  // has remainder so add one page
  $pages++;
  }

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link
  $news=$s+$limit;

  echo "<p> ;;<a href=\"$PHP_SELF?s=$news&q=$varsearch\">Next 10 &gt;&gt;</a></p>";
  }

$a = $s + ($limit) ;
  if ($a > $numrowssearch) { $a = $numrowssearch ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrowssearch</p>";

closetable();
include("footer.php");
?>



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum