My table is called : stories
among fields are: category and the fields mentioned in the array by code end
in category are depending on category a few different categories, one is " ag "
that the one I am presently interested in
and I want to display the data as per the array
however it results in "no results found etc..."
this si the query I seem to have a probem with
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' "
;
thank you
regards
here is the rest of the code
MISSING CONNECT CODE
if (!($limit)){
$limit = 10;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' "
;
// the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query - $query"
;
exit();}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows%$limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
//escape from PHP mode.
?>
<html>
<head>
<title>Search Results for <?=$query?></title>
</head>
<body>
<table width="100%" border="2" bgcolor="#ffffcc">
<tr>
<td align="left" colspan="4">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
Page <b><?=$current?></b> of <b><?=$total?></b>
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5"><b>5</b></a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10"><b>10</b></a>
</td>
</tr>
<!-- </table> -->
<?
//Go back into PHP mode.
// Now we can display results.
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' ORDER BY business_name ASC LIMIT $page, $limit"
;
while ($data = mysql_fetch_array($results))
{
?>
<tr>
<td width="100% align="top" valign="left" colspan="1"><P><font color="#cccccc" size="4"><I>AGRICULTURE & FOOD</I></font>
</td></tr>
<tr>
<td width="100%" align="left" valign="top"><font color="#990000" size="3">Business Name</font>: <?=$data["business_name"]?></font></td>
<tr>
<td width="100%" align="left" valign="top"><font color="#990000" size="3">Newsletter Name</font>: <?=$data["newsletter_name"]?></font></td>
<tr>
<td width="33%" align="left" valign="top"><font color="#990000" size="3">Newsletter</font>: <br>
<?=$data["newsletter_text"]?></font></td>
<tr>
<td width="100%" colspan="1">
<?
{ // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\"><align=left><font size=3>Next: Click here to jump to next page</a></font></hr>\n"
;}
?>
</tr>
</td>
<?
}
?>
<align="left">
<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n"
;}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b><hr size=5 align=left width=400>$i</b></hr> \n"
;} // If current page don't give link, just text.
else{
echo("<font size=4><a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a></font> \n"
;}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\"><hr size=5 align=left width=400><font size=5>next</a></font></hr>\n"
;}
?>
</table>
</body>
</html>
among fields are: category and the fields mentioned in the array by code end
in category are depending on category a few different categories, one is " ag "
that the one I am presently interested in
and I want to display the data as per the array
however it results in "no results found etc..."
this si the query I seem to have a probem with
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' "
thank you
regards
here is the rest of the code
MISSING CONNECT CODE
if (!($limit)){
$limit = 10;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' "
// the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query - $query"
exit();}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows%$limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
//escape from PHP mode.
?>
<html>
<head>
<title>Search Results for <?=$query?></title>
</head>
<body>
<table width="100%" border="2" bgcolor="#ffffcc">
<tr>
<td align="left" colspan="4">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
Page <b><?=$current?></b> of <b><?=$total?></b>
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5"><b>5</b></a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10"><b>10</b></a>
</td>
</tr>
<!-- </table> -->
<?
//Go back into PHP mode.
// Now we can display results.
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' ORDER BY business_name ASC LIMIT $page, $limit"
while ($data = mysql_fetch_array($results))
{
?>
<tr>
<td width="100% align="top" valign="left" colspan="1"><P><font color="#cccccc" size="4"><I>AGRICULTURE & FOOD</I></font>
</td></tr>
<tr>
<td width="100%" align="left" valign="top"><font color="#990000" size="3">Business Name</font>: <?=$data["business_name"]?></font></td>
<tr>
<td width="100%" align="left" valign="top"><font color="#990000" size="3">Newsletter Name</font>: <?=$data["newsletter_name"]?></font></td>
<tr>
<td width="33%" align="left" valign="top"><font color="#990000" size="3">Newsletter</font>: <br>
<?=$data["newsletter_text"]?></font></td>
<tr>
<td width="100%" colspan="1">
<?
{ // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\"><align=left><font size=3>Next: Click here to jump to next page</a></font></hr>\n"
?>
</tr>
</td>
<?
}
?>
<align="left">
<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n"
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b><hr size=5 align=left width=400>$i</b></hr> \n"
else{
echo("<font size=4><a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a></font> \n"
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\"><hr size=5 align=left width=400><font size=5>next</a></font></hr>\n"
?>
</table>
</body>
</html>