0

I'm creating search for my website.How should i give links of respective pages to the results that i m getting.

Pls Help.

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by NutanGadakh
0

Th answer to the question you ask depends on the way your website is structured.

Do you have several pages or are the pages being dynamically created from a DB?
Is your search algorithm returning the page_id's or the page names?

If you can post the code as to where you have a problem we might be able to help.

0

I have several pages whose content is displayed dynamically created from a DB.
search algorithm returns the page names not pageid's.
How should i search for all tables in DB and give the respective page link to those results
Pls Help.

0

Do you have a primary key for the DB from which you pull the pages. How would you access your pages in a browser? You should have something like http://www.example.com/page.php?page_name=page1 If that's the case then it would be easy to link to the pages. All you have to do would be to use <a href="http://www.example.com/page.php?page_name=<? echo $page['page_name'] ?>">Page1</a> You will of course have to change the variables depending on your code. The echo will give the reference of the page_name to the link.

If you still have a problem, post the code where you are pulling the search results, and I'll see how you can link your pages.

0
<?php 
// includes
session_start();
require('db/config.php');
$_SESSION["srch"] = trim($_GET["search"]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<form action="search1.php" method="get"><table border="0" align="center" cellpadding="3" cellspacing="3" width="99%" bgcolor="#999999">
 <tr><td width="674" align="right">Search:</td>
 <td width="124"><input type="Text" name="search" size="20" value="<?php $_GET["search"];?>" class="ctrl" ></td>
 <td width="120"> <input type="submit" name="Submit" value="Search" /></td></tr></table></form>
<table border="0" align="center" cellpadding="3" cellspacing="3" width="99%" bgcolor="#999999">
<tr><td>
<?php
if(isset($_GET["Submit"]) && empty($_GET["search"]))
{
	echo '<tr><td valign="top" align="center">Please enter a search value...</td></tr>';
	//exit;
}
elseif(isset($_GET["Submit"]) || !empty($_GET["search"]))
{
	$_SESSION["srch"] = trim($_GET["search"]);
	$var = $_SESSION["srch"];
	$my=mysql_query("select * from home_content where hc like \"%$var%\" ") or die(mysql_error($my));
	$rn=mysql_num_rows($my); 
	$myres=mysql_fetch_array($my);

if($rn>0)
	{
		if(!isset($_GET['pageno']))	{ $pageno=1; }
		else
		if ($_GET['pageno']==0  ) 	{	$pageno=1; 	}
		else 	{	$pageno=$_GET['pageno']; }
		if(!isset($_GET['pagesize'])) { $pagesize=1; }
		else
		if ($_GET['pagesize']==0 )	{	$pagesize=1; }
		else 	{	$pagesize=$_GET['pagesize'];} 
			if ($rn=mysql_num_rows($my)>0)
			{    $trecord=mysql_num_rows($my);
				if($trecord>1)
				{
					$pagecount=$trecord/1; 
					$pagecount= ceil($pagecount);
				}
				else
				{	
					$pagecount=1;
				}
			}//if 

			 if($pageno<>1)
			{ ?>  
		   <a href="search1.php?pageno=1&pagesize=1&search=<?php echo $var; ?>">First</a>&nbsp;&nbsp;
			<a href="search1.php?pageno=<?php echo $pageno-1; ?>&pagesize=1&search=<?php echo $var; ?>">Prev</a>
			<?php
			} ?>
			Page <?php  echo $pageno; ?> of  <?php echo $pagecount; 
			if($pageno<>$pagecount)
			{	?>
			<a href="search1.php?pageno=<?php echo $pageno+1; ?>&pagesize=1&search=<?php echo $var; ?>">Next</a>
			 <a href="search1.php?pageno=<?php  echo $pagecount; ?>&pagesize=1&search=<?php echo $var; ?>">Last</a>
			</td></tr>
		   <?php
			}
$reccount=0;
$e=$pageno * 1;
$l=$e-1;
$searchinfo = array();

	$viewQuery=mysql_query("select *  from home_content  where hc like \"%$var%\"  limit $l,1") or die(mysql_error());
		if(mysql_num_rows($viewQuery) > 0)
		{	
			while($Res = mysql_fetch_array($viewQuery))
			{
		?>
			<tr><td valign="top">
			<?php  
				foreach($Res as $key => $value)
				{
					$searchinfo[]['searchresult']=substr($Res["1"],0, 25);
					$searchinfo[]['pagelink']='home.php?pk='.$Res["2"];
				 ?>	<a href="<?php echo $searchinfo[]['pagelink']; ?>"><?php echo $searchinfo[]['searchresult']; ?></a>
				<?php
                }
			}//while
		}//if
	}//if
						
}
?>
             </td></tr>
</table>
This is my code i m getting error on line 89. i know i can't print array like this but i m not getting how should i print those values and also help me to write this code for multiple tables in same page.      
Pls Help

</body>
</html>
0
<?php 
// includes
session_start();
require('db/config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<form action="search3.php" method="get"><table border="0" align="center" cellpadding="3" cellspacing="3" width="99%" bgcolor="#999999">
 <tr><td width="674" align="right">Search:</td>
 <td width="124"><input type="Text" name="search" size="20" value="<?php if(isset($_GET["search"])) { echo  $_GET["search"]; } ?>" class="ctrl" ></td>
 <td width="120"> <input type="submit" name="Submit" value="Search" /></td></tr></table></form>
<table border="0" align="center" cellpadding="3" cellspacing="3" width="99%" bgcolor="#999999">
<tr><td>
<?php
if(isset($_GET["Submit"]) && empty($_GET["search"]))
{
    echo '<tr><td valign="top" align="center">Please enter a search value...</td></tr>';
    //exit;
}
elseif(isset($_GET["Submit"]) || !empty($_GET["search"]))
{
    $_SESSION["srch"] = trim($_GET["search"]);
    $var = $_SESSION["srch"];
    $my=mysql_query("select * from home_content where hc like \"%$var%\" ") or die(mysql_error($my));
    $rn=mysql_num_rows($my); 
    $myres=mysql_fetch_array($my);

if($rn>0)
    {
        if(!isset($_GET['pageno'])) { $pageno=1; }
        else
        if ($_GET['pageno']==0  )   {   $pageno=1;  }
        else    {   $pageno=$_GET['pageno']; }
        if(!isset($_GET['pagesize'])) { $pagesize=1; }
        else
        if ($_GET['pagesize']==0 )  {   $pagesize=1; }
        else    {   $pagesize=$_GET['pagesize'];} 
            if ($rn=mysql_num_rows($my)>0)
            {    $trecord=mysql_num_rows($my);
                if($trecord>1)
                {
                    $pagecount=$trecord/1; 
                    $pagecount= ceil($pagecount);
                }
                else
                {   
                    $pagecount=1;
                }
            }//if 

             if($pageno<>1)
            { ?>  
           <a href="search3.php?pageno=1&pagesize=1&search=<?php echo $var; ?>">First</a>&nbsp;&nbsp;
            <a href="search3.php?pageno=<?php echo $pageno-1; ?>&pagesize=1&search=<?php echo $var; ?>">Prev</a>
            <?php
            } ?>
            Page <?php  echo $pageno; ?> of  <?php echo $pagecount; 
            if($pageno<>$pagecount)
            {   ?>
            <a href="search3.php?pageno=<?php echo $pageno+1; ?>&pagesize=1&search=<?php echo $var; ?>">Next</a>
             <a href="search3.php?pageno=<?php  echo $pagecount; ?>&pagesize=1&search=<?php echo $var; ?>">Last</a>
            </td></tr>
           <?php
            }
$reccount=0;
$e=$pageno * 1;
$l=$e-1;
$searchinfo = array();

    $viewQuery=mysql_query("select *  from home_content  where hc like \"%$var%\"  limit $l,1") or die(mysql_error());
        if(mysql_num_rows($viewQuery) > 0)
        {   
            while($Res = mysql_fetch_array($viewQuery))
            {
        ?>
            <tr><td valign="top">
            <?php  
                foreach($Res as $key => $value)
                {
                    $searchinfo[]['searchresult']=substr($Res["1"],0, 25);
                    $searchinfo[]['pagelink']='home.php?pk='.$Res["2"];
                 ?> <a href="<?php echo $searchinfo[0]['pagelink']; ?>"><?php echo $searchinfo[0]['searchresult']; ?></a>
                <?php
                }
            }//while
        }//if
    }//if

}
?>
             </td></tr>
</table>

</body>
</html>

pls see this code some problem in below code im getting result but i want to search same for different tables.
pls help

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.