Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 04-18-2004, 03:56 PM
TouchingVirus's Avatar
TouchingVirus TouchingVirus is offline
 
Join Date: Nov 2001
Location: Bogland
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Another one..

Here is another one that has me half-stumped!

In vbulletin, especially, when i do custom queries, i usually get multiple rows of results..

Rather like this little snippet..

PHP Code:
$user $DB_site->query("SELECT * FROM user WHERE userid < 5");
$username $user['username']; 
This returns 4 rows if you have more than 5 users. The problem i have is to get it to display on a php page..

for instance, in that peice of code i want to display the usernames as follows in a template..

Username1
Username2
Username3
Username4

so in the template i put in this..

<table><td><strong>$username</strong></td></table>

Yet this will only display one username, not all 4 as i want it to appear..any ideas on how to print all 4?
Reply With Quote
  #2  
Old 04-18-2004, 04:01 PM
assassingod's Avatar
assassingod assassingod is offline
 
Join Date: Jul 2002
Posts: 3,337
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You will need to use a while loop:
PHP Code:
$user $DB_site->query("
    SELECT * FROM user WHERE userid < 5
"
);
    while(
$user $DB_site->fetch_array())
    {
        
$username $user['username']; 
        eval(
'$somevar .= "' fetch_template('YOUR_TEMPLATE') . '";');
    } 
Reply With Quote
  #3  
Old 04-18-2004, 04:08 PM
TouchingVirus's Avatar
TouchingVirus TouchingVirus is offline
 
Join Date: Nov 2001
Location: Bogland
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quick response, thanks for that Assassingod, i will try it straight away!
Reply With Quote
  #4  
Old 04-18-2004, 04:08 PM
assassingod's Avatar
assassingod assassingod is offline
 
Join Date: Jul 2002
Posts: 3,337
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No problem.
Reply With Quote
  #5  
Old 04-18-2004, 04:10 PM
TouchingVirus's Avatar
TouchingVirus TouchingVirus is offline
 
Join Date: Nov 2001
Location: Bogland
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works like a charm (not that i doubted ) Thanks so much assassingod
Reply With Quote
  #6  
Old 04-18-2004, 04:15 PM
assassingod's Avatar
assassingod assassingod is offline
 
Join Date: Jul 2002
Posts: 3,337
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by assassingod
No problem.
Reply With Quote
  #7  
Old 04-18-2004, 04:27 PM
TouchingVirus's Avatar
TouchingVirus TouchingVirus is offline
 
Join Date: Nov 2001
Location: Bogland
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, heres another one that hinged on that problem...i thought that the above would have sorted it out..but it didnt

I have the IP-to-country database.. i have a page with a country-dropdown box..pick a country in the box, and it displays the country's IP ranges..I am using an echo statement to show the ranges at the top of the page to verify..

PHP Code:
$query $DB_site->query("SELECT * FROM ip_to_country WHERE COUNTRY_CODE2='$cc'");
while (
$results $DB_site->fetch_array($query))
{
$ip_from long2ip($results[IP_FROM]);
$ip_to long2ip($results[IP_TO]);
$country $results[COUNTRY_NAME];
echo 
"$ip_from - $ip_to    ";
eval(
'$range_from = "' fetch_template('range_from') . '";');
eval(
'$range_to = "' fetch_template('range_to') . '";');
}
eval(
'print_output("' fetch_template('country_results') . '");');

The contents of range_to is

Code:
$ip_to
And range_from is similar ..

Yet when i run the code, it only displays the last IP-Range..rather like the first query only displayed the last username..the echo statement however displays all ranges as its supposed to"

Any ideas? I posted in Mod help too & bumped a few times, but nobody answered
Reply With Quote
  #8  
Old 04-18-2004, 04:30 PM
assassingod's Avatar
assassingod assassingod is offline
 
Join Date: Jul 2002
Posts: 3,337
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why use 2 templates instead of one? (Unless i've missed something)
Reply With Quote
  #9  
Old 04-18-2004, 04:44 PM
TouchingVirus's Avatar
TouchingVirus TouchingVirus is offline
 
Join Date: Nov 2001
Location: Bogland
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I changed it to use one..now code is as follows

PHP Code:
// Query for getting visitor countrycode
if (isset($_POST[submit]))
{
$cc $_POST['country'];
$query $DB_site->query("SELECT * FROM ip_to_country WHERE COUNTRY_CODE2='$cc'");
while (
$results $DB_site->fetch_array($query))
{
$ip_from long2ip($results[IP_FROM]);
$ip_to long2ip($results[IP_TO]);
$country $results[COUNTRY_NAME];
echo 
"$ip_from - $ip_to    ";
eval(
'$range_results = "' fetch_template('range_results') . '";');
}
eval(
'print_output("' fetch_template('country_results') . '");');

Range_Results Template:
Code:
<td class="alt1" width="50%"]>$ip_from</td>
<td class="alt2" width="50%">$ip_to</td>
Country_Results template
Code:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<!-- end no cache headers -->
<title>Country Results Page</title>
$headinclude
</head>
<body>
$header
$navbar
<!-- main --><table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td align="center" class="tcat">
IP Ranges For <i><u>$country</i></u></td>
</tr>
</table>
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<thead>
<tr align="center">	  
<td class="thead" width="50%" align="center">Range Start
</td>
<td class="thead" width="50%">Range End
</td>
</tr>
</thead>
<tr align="center">	  
$range_results
</tr>
</table>
<!-- /main -->
$footer
</body>
</html>
Reply With Quote
  #10  
Old 04-19-2004, 05:56 PM
TouchingVirus's Avatar
TouchingVirus TouchingVirus is offline
 
Join Date: Nov 2001
Location: Bogland
Posts: 76
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

any ideas Assassingod
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:00 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.04576 seconds
  • Memory Usage 2,269KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete