FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Some php probs..need some help plzz!





L-Amrani
hi all i am clicking some options in previous page to display the results in the next page am getting paging results but i am not able suppress start=1&start=2 which is blocking my desired output



someway i am getting following output in the browser

this is directed from

1st link http://localhost/aaa.php


2nd link http://localhost/111/test/bbb.php?s...y=5&b=1&t=1&d=1


where my error lies in the 2nd link

code as follows
[php ] if(!isset($start)) { // This variable is set to zero for the first page
$start = 1;
}

$eu = ($start - 0);
$limit = 3; // No of records to be shown per page.
$this = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;

$options=$_GET;
$c=1;
$paging='';
foreach($options as $key=>$page)
{
if($c==sizeof($options))
{
//$paging='';
$paging.=$key.'='.$page;

}
else
{
$paging.=$key.'='.$page.'&';
//echo "saigopal";
}
$c++;
}

$term=$_GET['terms'];
$keywords = split(' ' , $term);
if($options['st']==1)
if ($hf=fopen('stopwords.xml','r'))
{
for ($sfile='';$buf=fread($hf,4096))
{
$sfile.=$buf;
}
$A=XML_unserialize($sfile);
$stopword = split(' ' , $A['stopwords']);
foreach($stopword as $w1)
{
foreach($keywords as $key=>$w2)
{
if(strcmp($w1,$w2)==0)
{
unset($keywords[$key]);
}
}
}
}
foreach($keywords as $keyword) {
if($options['w']!=1) {
if($options['t']==1) {
$qArray[] = "title LIKE '%$keyword%'";
}
if($options['u']==1) {
$qArray[] = "url LIKE '%$keyword%'";
}
if($options['alt']==1) {
$qArray[] = "alttext LIKE '%$keyword%'";
}
if($options['d']==1) {
$qArray[] = "metadescription LIKE '%$keyword%'";
}
if($options['k']==1) {
$qArray[] = "metakeywords LIKE '%$keyword%'";
}
if($options['b']==1) {
$qArray[] = "content LIKE '%$keyword%'";
}
if($options['l']==1) {
$qArray[] = "links LIKE '%$keyword%'";
}
}elseif($options['w']==1) {
if($options['t']==1) {
$qArray[] = "title LIKE '$keyword'";
}
if($options['u']==1) {
$qArray[] = "url LIKE '$keyword'";
}
if($options['alt']==1) {
$qArray[] = "alttext LIKE '$keyword'";
}
if($options['d']==1) {
$qArray[] = "metadescription LIKE '$keyword'";
}
if($options['k']==1) {
$qArray[] = "metakeywords LIKE '$keyword'";
}
if($options['b']==1) {
$qArray[] = "content LIKE '$keyword'";
}
if($options['l']==1) {
$qArray[] = "links LIKE '$keyword'";
}
}
if ((isset($qArray)) && (sizeOf($qArray>0))) {
$qString = ' where ';
$qString .= implode(" or ", $qArray);

$resource=tep_db_query("select * from files".$qString. " order by file_id limit $eu,$limit");
$resource1=tep_db_query("select * from files".$qString. " order by file_id");
$rows=tep_db_num_rows($resource1);

}else {
$resource=tep_db_query("select * from files order by file_id");
}
while($results=tep_db_fetch_array($resource)) {
$res[$results[file_id]]['title']=$results['title'];
$res[$results[file_id]]['url']=$results['url'];
$res[$results[file_id]]['filesize']=$results['filesize'];
}
}
$sum=0;

for($l=0;$l<count($res);$l++)
{
$sum+=$res[$l]->wordcount;
}

function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();
for ($i=0; $i < 1000; $i++) {
// do nothing, 1000 times
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Your Search Results</title>
<style>
A:link {color: #000066; text-decoration: none }
A:visited {color: #000066; text-decoration: none}
A:active {color: red; text-decoration: underline}
A:hover {color: red; text-decoration: underline}
</style>
</head>
<body>

<table border="0" cellpadding="5" cellspacing="0" bgcolor="#cccccc" width="95%" align="center">
<tr>
<td width="73%"><font color="#000000" size=2 face="verdana, arial, helvetica, sans-serif">
Results <b><?php
$results=sizeof($res);
echo $results;?></b> for <b><?php echo $_GET['terms'];?></b> with <b><?php echo $sum;?></b> total matches
<br>Searched:
<b>
<?php if($_GET['b']==1)
{
echo "Body ";
}
if($_GET['t']==1)
{
echo "Title ";
}
if($_GET['d']==1)
{
echo "Meta-Description ";
}
if($_GET['k']==1)
{
echo "Meta-Keywords ";
}
if($_GET['k']==1)
{
echo "Meta-Keywords ";
}
if($_GET['l']==1)
{
echo "Links ";
}
if($_GET['u']==1)
{
echo "Url ";
}
if($_GET['alt']==1)
{
echo "Alt-text ";
}


?></b>
<br>Required Time: <b><?php echo $time;?> seconds</b>
</font></td>
<td valign=top align=right nowrap width="27%"><font size=2 face="verdana, arial, helvetica, sans-serif"><b><a href="http://www.blah.com">Return
to Home Page</a>&nbsp;
<a href="#form" alt="To Search Form" title="To Search Form" onclick="document.search.terms.focus()">Form</a>
&nbsp;
<a href="http://www.blah.com/cgi-bin/sitesearch/search.cgi?terms=spyware&p=1&help=1&display=10&b=1&t=1&d=1&sort=Matches" title="Search Tips" alt="Search Tips" class="help"><b>Tips</b></a>
</b></font></td>
</tr>
</table>
Here are your search results


<table align = 'center' width='50%'><tr><td align='left' width='30%'>
<?php

//if($back >=0) {
?>
<a href='search.php?start=<?=$back;?>&<?=$paging;?>'><font face='Verdana' size='2'>PREV</font></a>
<?php // }?>

</td><td align=center width='30%'>
<?php

$l=1;
for($i=1;$i<$results;$i++){

if($i <> $eu){


?>
<a href='search.php?start=<?=$i;?>&<?=$paging;?>'><font face='Verdana' size='2'><?=$l;?></font></a>

<?php

}
else {
?>
<font face='Verdana' size='4' color=red><?=$l;?></font><?php }
$l=$l+1;
}
?>

</td><td align='right' width='30%'>
<?php
if($this < $results) { ?>
<a href='search.php?start=<?=$next;?>&<?=$paging;?>'><font face='Verdana' size='2'>NEXT</font></a>

<?php
}
?>

</td></tr></table>



<table width="95%" border="0" align="center">
<tr>
<td>
<?php
$k=1;
foreach($res as $key=>$value)
{
?>
<dl>

<dt><font color="#000000" size=2 face="verdana, arial, helvetica, sans-serif"><b>
<?php echo $k;?>
. &nbsp; <a href="<?php echo $value['url'];?>">
<?php echo $value['title'];?>
</a></b></font></dt>
<dd>

<font size="1" color="#000000" face="verdana, arial, helvetica, sans-serif"><a href="<?php echo $value['url'];?>">
<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/'.$value['url'];?>
</a><br>
<b>Matches:</b> <?php echo $res[$l]->wordcount;?>
&nbsp;
<!--<b>Score:</b> 3.24-->
&nbsp;

&nbsp;
<b>File Size:</b> <?php echo $value['filesize'];?>KB
</font> </dd>
</dl>
<?php $k++; }
?>[/ php ]

please urgent
sai gopal
BlackSkad
Your code is quite huge, and I don't realy understand your problem.

But a quick look showed that you use $start whitout declaring it. !isset($start) will always be false. You need to do it as below:
Code:
if (!isset($_GET['start'])
    $start = $_GET['start'];
else
    $start = 1;
SirDuncan
can you explain a little more your problem ?
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.