vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Display MySQL Query result (https://vborg.vbsupport.ru/showthread.php?t=41855)

Keith 08-03-2002 11:35 AM

Display MySQL Query result
 
This is my query

Code:

$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 11:52 AM

PHP Code:

$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 12: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
Code:

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

}


Keith 08-03-2002 12:37 PM

Forgot to say "thanks for the reply" in my other message. Here''s the whole piece which may help.

Code:

// ############    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 12: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 01:15 PM

Thanks again Xenon. The result is simply the word ARRAY. :(

I'll keep tweaking.

Keith 08-03-2002 01: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:
Code:

<tr align='center'>
        <td bgcolor='{firstaltcolor}'>$boatbrand[countboats] - $boatbrand[boatbrands]</td>
        </tr>


Xenon 08-03-2002 10:15 PM

:)
you're welcome


All times are GMT. The time now is 04:15 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02743 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete