Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query problem

Status
Not open for further replies.

cabernet

Technical User
Feb 24, 2003
75
PK
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=&quot;100%&quot; border=&quot;2&quot; bgcolor=&quot;#ffffcc&quot;>
<tr>
<td align=&quot;left&quot; colspan=&quot;4&quot;>
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>

    Page <b><?=$current?></b> of <b><?=$total?></b>

    Results per-page: <a href=&quot;<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5&quot;><b>5</b></a> | <a href=&quot;<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10&quot;><b>10</b></a>
</td>
</tr>
<!-- </table> -->
<?
//Go back into PHP mode.

// Now we can display results.
$numresults = mysql_query(&quot;SELECT category FROM stories where category = '%ag&quot;. $query .&quot;%' ORDER BY business_name ASC LIMIT $page, $limit&quot;);

while ($data = mysql_fetch_array($results))
{
?>

<tr>
<td width=&quot;100% align=&quot;top&quot; valign=&quot;left&quot; colspan=&quot;1&quot;><P><font color=&quot;#cccccc&quot; size=&quot;4&quot;><I>AGRICULTURE & FOOD</I></font>
</td></tr>
<tr>
<td width=&quot;100%&quot; align=&quot;left&quot; valign=&quot;top&quot;><font color=&quot;#990000&quot; size=&quot;3&quot;>Business Name</font>: <?=$data[&quot;business_name&quot;]?></font></td>
<tr>
<td width=&quot;100%&quot; align=&quot;left&quot; valign=&quot;top&quot;><font color=&quot;#990000&quot; size=&quot;3&quot;>Newsletter Name</font>: <?=$data[&quot;newsletter_name&quot;]?></font></td>
<tr>
<td width=&quot;33%&quot; align=&quot;left&quot; valign=&quot;top&quot;><font color=&quot;#990000&quot; size=&quot;3&quot;>Newsletter</font>: <br>
<?=$data[&quot;newsletter_text&quot;]?></font></td>

<tr>
<td width=&quot;100%&quot; colspan=&quot;1&quot;>
<?
{ // If last page don't give next link.
$next_page = $page + $limit;
echo(&quot;<a href=\&quot;$PHP_SELF?query=$query&page=$next_page&limit=$limit\&quot;><align=left><font size=3>Next: Click here to jump to next page</a></font></hr>\n&quot;);}

?>
</tr>
</td>

<?
}
?>
<align=&quot;left&quot;>
<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo(&quot;<a href=\&quot;$PHP_SELF?query=$query&page=$back_page&limit=$limit\&quot;>back</a> \n&quot;);}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo(&quot;<b><hr size=5 align=left width=400>$i</b></hr> \n&quot;);} // If current page don't give link, just text.
else{
echo(&quot;<font size=4><a href=\&quot;$PHP_SELF?query=$query&page=$ppage&limit=$limit\&quot;>$i</a></font> \n&quot;);}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(&quot;<a href=\&quot;$PHP_SELF?query=$query&page=$next_page&limit=$limit\&quot;><hr size=5 align=left width=400><font size=5>next</a></font></hr>\n&quot;);}
?>
</table>
</body>
</html>
 
I have none of the error as described in your primer
(good debug function thanks)

I comunicate fine with the DB

since I made some modif
it displays the page ordering but still no data from DB

TOP of CODE
$numresults = mysql_query(SELECT business_name, newsletter_name, newsletter_text from stories where category like 'ag&quot;.$query.&quot;%' &quot;);

//Now we display results
$numresults = mysql_query(SELECT business_name, newsletter_name, newsletter_text from stories where category like 'ag&quot;.$query.&quot;%' ORDER BY business name ASC LIMIT $page,$limit&quot;);
 
I need to work on the section on databases.

One thing you are not doing is checking for errors as you query. The simplest way is:

$result = mysql_query ($some_query) or die (mysql_error());

You may be having errors in your query.

Also, output the concatenated query to the browser. Cut and paste to your preferred MySQL admin app and see whether you get the behavior you expect.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
well
I tried a simple query and it worked fine
so the problem has to be in the display not in conn to DB

thanks
 
Don't assume. Verify.

Have you verified that the problem is not your query? Have you run the query produced by your code's string concatenation in a MySQL admin tool, and gotten the return you expect?

The best code in the world won't work right if it doesn't have the right data wor work with.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I used PHP My admin
the query went OK no problem here
 
sleipnir 214
thanks I fixed it
I had once $results
and once $numresults

I know I will hit myself a few times
however you pointed me to a few good tools
and forced me to re re re read my code :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top