Hi all!
I have this problem with MacSQL and the Web Script Assistant.
The Batch doesn work properly: I get the correct hits in the list as well as the batch-links in the bottom of the list, but the number om rows shown in the list is not what i specified: I get ALL the hits on ALL the batch-pages.
Anyone who understands more than I do and know what to do?
Regards / G
The search-page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HEAD>
<TITLE>Search</TITLE>
</HEAD>
<BODY>
<FORM METHOD="get" ACTION="results.php" NAME="searchForm"><INPUT TYPE="hidden" NAME="so0" VALUE="contains">
<TABLE>
<TR>
<TD>
<SELECT NAME="sf0"><OPTION VALUE="Content">Content</OPTION>
</SELECT>
</TD>
<TD>
</TD>
<TD>
<INPUT TYPE="text" NAME="ss0" SIZE="20" MAXLENGTH="40">
</TD>
</TR>
<TR>
<TD COLSPAN="3">
Batch Size: <SELECT NAME=bs><OPTION SELECTED>10</OPTION><OPTION>20</OPTION><OPTION>30</OPTION><OPTION>40</OPTION></SELECT>
</TD>
</TR>
<TR>
<TD ALIGN="center" COLSPAN="3">
<INPUT TYPE="submit" NAME="do" VALUE="Search">
</TD>
</TR>
</TABLE>
<INPUT TYPE="hidden" NAME="_ds" VALUE="1"><INPUT TYPE="hidden" NAME="bn" VALUE="0"></FORM>
</BODY>
The Result page (db, id, and password is left out):
<?PHP
function buildCondition($fld, $op, $val) {
$val = AddSlashes($val);
$cond = "";
$flds = preg_split("/,/", $fld);
for ($i=0; $i < count($flds); $i++) {
if ($i > 0) {
$cond .= " or ";
}
if (preg_match("/s/", $op)) {
$cond .= "$flds[$i] like '$val%'";
} else if (preg_match("/c/", $op)) {
$cond .= "$flds[$i] like '%$val%'";
} else if (preg_match("/e/", $op)) {
$cond .= "$flds[$i] like '%$val'";
} else if (preg_match("/i/", $op)) {
$cond .= "$flds[$i] = '$val'";
} else {
$cond .= "$flds[$i] $op $val";
}
}
return $cond;
}
$FormDict = $HTTP_GET_VARS;
if ($HTTP_POST_VARS['fs0']) {
$FormDict = $HTTP_POST_VARS;
}
$fields = array("Content");
$prettyFields = array("Content");
$fieldTypes = array(1);
$haveResults = 0;
$batchSize = $FormDict['bs'];
if ($batchSize < 2) {
$batchSize = 10;
}
$batchNum = $FormDict['bn'];
$maxBatches = 5;
if($FormDict['_ds']) {
mysql_pconnect("xxxx", "xxxx","xxxx");
mysql_select_db("xxxx");
$query = "select ID, tumme from bilder where ";
$query .= buildCondition($FormDict['sf0'], $FormDict['so0'], $FormDict['ss0']);
if ($FormDict['ss1']) {
$query .= $FormDict['sc0'] . buildCondition($FormDict['sf1'], $FormDict['so1'], $FormDict['ss1']);
}
if ($rs = mysql_query($query)) {
$rowCount = mysql_num_rows($rs);
if ($maxBatches > ($rowCount / $batchSize)) {
$maxBatches = (int)$rowCount / $batchSize;
}
for ($b=0; $b < $batchSize * $batchNum; $b++) {
mysql_fetch_row($rs);
}
if ($row = mysql_fetch_row($rs)) {
$haveResults = 1;
} else {
$haveResults = -1;
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HEAD>
<TITLE>Search Results</TITLE>
</HEAD>
<BODY>
<?PHP if ($haveResults == 0) { ?>
<P>No entries match your search critera.</P>
<?PHP } ?>
<?PHP if ($haveResults == 1) { ?>
<TABLE BORDER = "1" CELLPADDING="2">
<TR VALIGN="center">
<TH>tumme</TH>
</TR>
<?PHP $numShown = 0;
do { ?>
<TR VALIGN="center">
<TD><A HREF="details.php?k=<?PHP echo $row[0] ?>"><?PHP echo $row[1] ?></A></TD>
</TR>
<?PHP } while (($row = mysql_fetch_row($rs)) && ($numShown < $batchSize)); ?>
<TR ALIGN="center"><TD COLSPAN=1><?PHP
$bcode = '';
if ($maxBatches > 1) {
$url = $SCRIPT_NAME . '?' . $QUERY_STRING;
if (preg_match("/bs=\d/", $url)) {
$bn=(int)$FormDict['bn'];
for ($b=0; $b < $maxBatches; $b++) {
if($b > 0) { $bcode .= ' | '; }
if ($b == $bn) {
$bcode .= "<B>" . ($b+1) . "</B>";
} else {
$url = preg_replace("/bn=\d+/", "bn=$b", $url);
$bcode .= "<A HREF=\"$url\">" . ($b+1) . "</A>";
}
}
}
}
echo $bcode;
?></TD></TR>
</TABLE>
<?PHP } ?>
</BODY>
And the Detail page. No problem here... I think:
<?PHP
$FormDict = $HTTP_GET_VARS;
$fields = array ("namn");
$haveResults = 0;
if($FormDict['k']) {
mysql_pconnect("xxxx", "xxxx","xxxx");
mysql_select_db("xxxx");
$query = "select namn from bilder where ID = " . $FormDict['k'];
if ($rs = mysql_query($query)) {
if ($data = mysql_fetch_row($rs)) {
$haveResults = 1;
} else {
$haveResults = -1;
}
}
}?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HEAD>
<TITLE>Details</TITLE>
</HEAD>
<BODY>
<TABLE CELLSPACING=4>
<?PHP for ($i=0; $i < 1; $i++) { ?>
<TR>
<TD><B><?PHP echo $fields[$i]; ?></B></TD>
<TD><?PHP echo $data[$i]; ?></TD>
</TR>
<?PHP } ?>
</TABLE>
</BODY>