Forum Moderators: coopster
<<<
$numresults = mysql_query("SELECT category FROM stories where category = ag '%". $query ."%' ");
>>>
category is a field
stories is the table's name
and ag is a category populating category field among other categories
so the idea is to get all "ag"
thanks
Regards
$numresults = mysql_query("SELECT category FROM stories where category = 'ag'");
But it looks like you are doing a like 'ag' so try:
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' ");
But if they all start with 'ag' try this although I have never tried like as a sub:
$numresults = mysql_query("SELECT category FROM stories where category = 'ag%". $query ."%' ");
$numresults = mysql_query("SELECT category FROM stories where category = '%ag". $query ."%' ");
But if they all start with 'ag' try this although I have never tried like as a sub:
$numresults = mysql_query("SELECT category FROM stories where category = 'ag%". $query ."%' ");
>>
whch show the building of the page but not anything out of the DB at least no more "No results found .."
yes there is a field named category and among many categories one reads " ag "
so that is all the "ag" related I expect to display
here is the rest of amy code that works well under other DB
of course spelling and DB are matching
the requirements
what's not showing is the connect top atop 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 like '%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 like '%ag". $query ."%' ORDER BY bussiness_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");}
?>
Change it here:
// Now we can display results.
$numresults = mysql_query("SELECT * FROM stories where category like '%ag". $query ."%' ORDER BY bussiness_name ASC LIMIT $page, $limit");
You really should only pull the results you want so maybe this would be better:
// Now we can display results.
$numresults = mysql_query("SELECT business_name, newsletter_name, newsletter_text FROM stories where category like '%ag". $query ."%' ORDER BY bussiness_name ASC LIMIT $page, $limit");
JAG
>>
it displays the page ordering system but no data
and no DB error
I doubled check all DB nields anme and array names
I cannot find a reason
the code is pretty straight forward
and makes sense so?
Try this:
$numresults = mysql_query("SELECT business_name, newsletter_name, newsletter_text FROM stories");
while($row = mysql_fetch_assoc($numresults)){
echo $row['business_name'];
echo $row['newsletter_name'];
echo $row['newsletter_text'];
}
Just to see if you are getting data.
If you are then do this:
$numresults = mysql_query("SELECT business_name, newsletter_name, newsletter_text FROM stories where category like '%ag%'");
while($row = mysql_fetch_assoc($numresults)){
echo $row['business_name'];
echo $row['newsletter_name'];
echo $row['newsletter_text'];
}
If you are getting data then there is something wrong with the call to the db I'm guessing. Try those first. Just to make sure you can get some data.
JAG