PDA

View Full Version : Display MySQL Query result


Keith
08-03-2002, 12:35 PM
This is my query

$boatbrands=$DB_site->query('select count(*)
AS countboats, field6 as boatbrands FROM userfield
WHERE field6 <> "n/a" AND field6 <> "n" AND field6 <> "none"
AND field6 <> "NA"
GROUP by field6
ORDER BY 1 DESC LIMIT 10');

Now how to display the results of this query? I've added an eval dooutput to a template at the bottom, but the results are showing up as the word "Array" when I use "query_first, and "resource ID #38" when I use "query". I don't think I'm supposed to use query_first because that will only return the first row.

The result is supposed to be 10 rows of 2 columns worth of data, but I can't figure out what I'm doing wrong here.

Xenon
08-03-2002, 12:52 PM
$boatbrands=$DB_site->query('select count(*)
AS countboats, field6 as boatbrands FROM userfield
WHERE field6 <> "n/a" AND field6 <> "n" AND field6 <> "none"
AND field6 <> "NA"
GROUP by field6
ORDER BY 1 DESC LIMIT 10');
while($boatbrand=$DB_site->fetch_array($boatbrands)) {
// enter here your output orders/ template bits or something like that
}

Keith
08-03-2002, 01:33 PM
I've been using some examples in other php files and the PHP man to learn the output piece, but even though I think I've got that right, I'm still getting the Resource ID #38 error in the output. Where can I find what the error is really trying to tell me?

Here's what I'm using for the output
while($boatbrand=$DB_site->fetch_array($boatbrands)) {

$boatbrand=$boatbrand["$boatbrands"];

}

Keith
08-03-2002, 01:37 PM
Forgot to say "thanks for the reply" in my other message. Here''s the whole piece which may help.

// ############ How many of each brand of boats

$boatbrands=$DB_site->query('select count(*)AS countboats, field6 as boatbrands FROM userfield
WHERE field6 <> "n/a" AND field6 <> "n" AND field6 <> "none" AND field6 <> "NA"
GROUP by field6
ORDER BY 1 DESC LIMIT 10');

while($boatbrand=$DB_site->fetch_array($boatbrands)) {
$boatbrands=$boatbrands["boatbrands"];

}


eval("dooutput(\"".gettemplate("boatstats_stats")."\");");

}

The template has the variable $boatbrands

Xenon
08-03-2002, 01:42 PM
use $boatbits in your boatstats_stats template

then change the code to:
[code]while($boatbrand=$DB_site->fetch_array($boatbrands)) {
eval("\$boatbits .= \"".gettemplate("boatbit")."\";");

}[/php]

then create a new template called boatbit and there use the variable $boatbrand

Keith
08-03-2002, 02:15 PM
Thanks again Xenon. The result is simply the word ARRAY. :(

I'll keep tweaking.

Keith
08-03-2002, 02:59 PM
GOT IT!!!

Xenon, many many thanks my friend. I was finally able to get it to display. I was, of course, doing a lot of things wrong and I sincerely appreciate your help.

Here was went into the boatbit template:
<tr align='center'>
<td bgcolor='{firstaltcolor}'>$boatbrand[countboats] - $boatbrand[boatbrands]</td>
</tr>

Xenon
08-03-2002, 11:15 PM
:)
you're welcome