Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Posts posted by DeanWhitehouse

  1. Search engines have no clue whether the directory exists or not. They don't see the server, they only see the data that the server feeds to them. Mod rewrite is set up on the server, and any rewriting is done internally before being sent to the search engines (or user). So whether a directory exists, or whether mod rewrite just makes it look like a directory exists, it doesn't really matter.

     

    No, that is not what i meant when you use it in links and/or submit them as pages in your site map it can make the search engine believe it is a directory and in effect come up with a 404

  2. Huh?

    Did you read what i wrote, the latest reply will be on the last page but i need to get to a specific reply which might be on the third.

     

    Normally (without pagination)

     

    I would do

     

    site.com/file.php#reply_5

    or something but with pagination that wouldn't work, i would need the page number.

  3. Just a little warning, first off not all hosts will allow mod rewrite, second off i believe it can cause problems with some search engines as it looks for a directory then and not a file, and third if the user or you try and use

     

    site.com/productname/

     

    it won't work it has to be

     

    site.com/productname

  4. O ok, well i modified this one so it similar (a bit) to mine.

     

    <form action="search1.php" method="get" name="search">
      <div align="center">
          <input name="q" type="text" value="<?php echo $q; ?>" size="15">
          <input name="search" type="submit" value="Search">
      </div>
    </form>
    <p>
    <?php 
    //connect to database 
    $hostname="host";
    $username="user";
    $password="********";
    $dbname="users";
    
    //open database connection
    mysql_connect($hostname,$username,$password);
    mysql_select_db($dbname);
    
    //specify how many results to display per page
    $limit = 10;
    
    // Get the search variable from URL
    if(isset($_GET['q']))
    $var = $_GET['q'] ;//Removed the @ as this suppresses errors, better to use an if statment
    else
    echo "You must enter a search parameter";//message to print if there is no get var passed
    
    //only allow alphanumeric ***--> I probably screwed this up but it seems to work except it displays "no record of found" when submitted with nothing in the search bar
    if (!ereg("^[A-z0-9]*[']?[A-z0-9]*$",$var))
    {
    //trim whitespace from the stored variable
    $trimmed = trim($var);
      
    //separate key-phrases into keywords
    $trimmed_array = explode(" ",$trimmed); 
    
    // check for an empty string and display a message.
    if (strlen($trimmed) == 0) 
    	$resultmsg =  "<p><b>SEARCH ERROR</b></p><p>Only enter letters or numbers: no spaces, dashes or special characters</p>" ;
    
    $row_count = 0;
    
    // Build SQL Query for each keyword entered 
    foreach ($trimmed_array as $trimm)
    {
          
    	// EDIT HERE and specify your table and field names for the SQL query
         $query = "SELECT * FROM table_1 WHERE field_1 LIKE '\"$trimm\"' ORDER BY field_1 DESC" ; 
    
    	// Execute the query to  get number of rows that contain search kewords
         $numresults = mysql_query ($query) or die ("Couldn't execute query: Reason; ".mysql_error());
         $row_num_links_main =mysql_num_rows ($numresults);
    	 $row_count += $row_num_links;
    
    // next determine if 's' has been passed to script, if not use 0.
    // 's' is a variable that gets set as we navigate the search result pages.
        if(!isset($s)) 
    		$s=0;
    
        // now let's get results.
        $query .= " LIMIT $s,$limit" ;
    	$numresults = mysql_query ($query) or die ("Couldn't execute query: Reason; ".mysql_error());
    	while($row = mysql_fetch_array($numresults))
    	{
    		echo "<b>Serial: </b>" . $row['id'];//enter the proper row names
    		echo "<b>Make: </b>" . $row['fname'];
    		echo "<b>Model: </b>" . $row['model'];
    		echo "<b>Caliber: </b>" . $row['city'];
    		echo "<b>Caliber: </b>" . $row['state'];
    	}
    } 
    //end foreach
    ?>
    </p>
    

     

    It might need some work, here is my search feature used on my site

     

    	<div class="post">
    		<h1 class="title">Search</h1>
    		<div class="entry">
    			<p>	
    				<form id="searchform" method="get" action="">
    						<input type="text" maxlength="20" name="query" id="s" size="15" value="<?php if(isset($_GET['query'])){echo $_GET['query'];}?>" >
    						<br>
    						<input type="submit" value="Search" id="x" >
    				</form>
    		</div>
    	</div>
    <?php
    if(isset($_GET['query']))
    {
    $search = stripslashes($_GET['query']);
    $search = mysql_real_escape_string($search);
    $search = trim($search);
    if(strlen($search) < 2)
    	echo "<div class=\"entry\">Please enter two or more values to perform a search</div>";
    else
    {
    	$sql = "SELECT COUNT(*) FROM djw_snippet WHERE `title` LIKE '%".$search."%'  OR `poster` LIKE '%".$search."%' OR `desc` LIKE '%".$search."%'";
    	$result = mysql_query($sql);
    	$r = mysql_fetch_row($result);
    	$numrows = $r[0];
    
    	// number of rows to show per page
    	$rowsperpage = 10;
    	// find out total pages
    	$totalpages = ceil($numrows / $rowsperpage);
    
    	// get the current page or set a default
    	if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
    	   // cast var as int
    	   $currentpage = (int) $_GET['currentpage'];
    	} else {
    	   // default page num
    	   $currentpage = 1;
    	} // end if
    
    	// if current page is greater than total pages...
    	if ($currentpage > $totalpages) {
    	   // set current page to last page
    	   $currentpage = $totalpages;
    	} // end if
    	// if current page is less than first page...
    	if ($currentpage < 1) {
    	   // set current page to first page
    	   $currentpage = 1;
    	} // end if
    	if($totalpages > 1)
    	echo "<div class=\"post\"><h2 class=\"title\">Page $currentpage out of $totalpages</h2></div>";
    
    	// the offset of the list, based on current page 
    	$offset = ($currentpage - 1) * $rowsperpage;
    
    
    	// get the info from the db 
    	$sql = "SELECT * FROM `djw_snippet` WHERE `title` LIKE '".$search."'  OR `poster` LIKE '%".$search."%' OR `tags` LIKE '%".$search."%'  ORDER BY time DESC LIMIT $offset, $rowsperpage";//removed OR `example` LIKE '%".$search."%' and OR `code` LIKE '%".$search."%'
    	$result = mysql_query($sql);
    
    	// while there are rows to be fetched...
    		$snip_count = mysql_num_rows($result);
    		if(strlen($search) > 30)
    			$r = substr($search,0,30)."...";
    		else
    			$r = $search;
    		if($snip_count == 1)
    			$c = $snip_count." result found - ";
    		else
    			$c = $snip_count." results found - ";
    		echo "<p class=\"byline\">".$c.$r."</p><div class=\"entry\">";
    		if($snip_count == 0)
    		{
    			echo "<br>Sorry there are no results that match your criterea";
    		}	
    		else
    		{	
    			while($rows = mysql_fetch_assoc($result))
    			{
    				$tags = $rows['tags'];	
    
    				if(substr_count(strtolower($tags),strtolower($search)) > 1)
    				{
    					$pos = stripos($tags,$search);
    					$len = strlen($search);
    					$tags = substr_replace($tags,"",$pos,$len);
    				}
    
    				$tags = str_replace(","," - ",$tags);
    				$tags = str_ireplace($search,"<b style=\"color:#FFFFFF;\">".$search."</b>",$tags);	
    				$title = ucfirst($rows['title']);
    
    				echo "<br><a href=\"http://djw-webdesign.awardspace.com/code.php?snippet=".$rows['id']."\">".$title."</a> - Posted by ".ucfirst($rows['poster'])."<br>  Tags: ".$tags;
    			}
    		}
    			echo "</div></div>";		
    
    
    	/******  build the pagination links ******/
    	// range of num links to show
    	$range = 3;
    
    	// if not on page 1, don't show back links
    	if ($currentpage > 1) {
    		if($totalpages > 2)
    	   echo " <a href='{$_SERVER['PHP_SELF']}?query=$search&currentpage=1'><<</a> ";
    	   // get previous page num
    	   $prevpage = $currentpage - 1;
    	   // show < link to go back to 1 page
    	   echo " <a href='{$_SERVER['PHP_SELF']}?query=$search&currentpage=$prevpage'><</a> ";
    	} // end if 
    
    	// loop to show links to range of pages around current page
    	for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
    	   // if it's a valid page number...
    	   if (($x > 0) && ($x <= $totalpages)) {
    	      // if we're on current page...
    	      if ($x == $currentpage) {
    			if($totalpages > 1)
    	         echo " [<b>$x</b>] ";
    	      // if not current page...
    	      } else {
    	         // make it a link
    		 echo " <a href='{$_SERVER['PHP_SELF']}?query=$search&currentpage=$x'>$x</a> ";
    	      } // end else
    	   } // end if 
    	} // end for
    
    	// if not on last page, show forward and last page links	
    	if ($currentpage != $totalpages) {
    	   // get next page
    	   $nextpage = $currentpage + 1;
    	    // echo forward link for next page 
    			if($totalpages > 1)		
    	   echo " <a href='{$_SERVER['PHP_SELF']}?query=$search&currentpage=$nextpage'>></a> ";
    	if($totalpages > 2)
    	   echo " <a href='{$_SERVER['PHP_SELF']}?query=$search&currentpage=$totalpages'>>></a> ";
    	} // end if
    	/****** end build pagination links ******/
    }	
    }
    ?>
    
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.