vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   simple while statement/query not working (https://vborg.vbsupport.ru/showthread.php?t=107598)

Nullifi3d 02-09-2006 10:53 PM

simple while statement/query not working
 
PHP Code:

$links $db->query_first("SELECT pl_href AS href, pl_title AS title, pl_anchor AS anchor FROM " TABLE_PREFIX "user WHERE pl_href != ''");
while (
$link $db->fetch_array($links)) eval('$premium_links = "' fetch_template('directory_premium_links') . '";'); 

I've added the three fields you see above to the user table so I can print out a list of websites on a certain page. However, when I use query_first it doesn't print anythign out. When I use query_read it only prints out the last link that would show (because read is not an array function). Why doesn't it work with first?

tnguy3n 02-09-2006 10:56 PM

TRY:
PHP Code:

$links $db->query("SELECT pl_href AS href, pl_title AS title, pl_anchor AS anchor FROM " TABLE_PREFIX "user WHERE pl_href != ''");
while (
$link $db->fetch_array($links))
{
    eval(
'$premium_links .= "' fetch_template('directory_premium_links') . '";');



Marco van Herwaarden 02-10-2006 07:47 AM

Quote:

Originally Posted by Nullifi3d
When I use query_read it only prints out the last link that would show (because read is not an array function).

To print all when using query_read(), change the eval statement to:
PHP Code:

eval('$premium_links .= "' fetch_template('directory_premium_links'

Quote:

Originally Posted by Nullifi3d
Why doesn't it work with first?

Because you don't need the while-statement or the fetch_array() if you're using query_first. query_first will already restrieve the row (query_first never return more then 1 row). With query_first you would need just (asuming your query would never return more then 1 row:
PHP Code:

 $link $db->query_first("SELECT pl_href AS href, pl_title AS title, pl_anchor AS anchor FROM " TABLE_PREFIX "user WHERE pl_href != ''"); 
eval(
'$premium_links = "' fetch_template('directory_premium_links') . '";'); 

Quote:

Originally Posted by tnguy3n
$links = $db->query

'query' is depreciated in vB3.5, use query_read or query_write instead.

Nullifi3d 02-10-2006 01:05 PM

thanks. I got it to work by adding the decimal before the =


All times are GMT. The time now is 08:31 AM.

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.01069 seconds
  • Memory Usage 1,728KB
  • 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_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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