vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Another one.. (https://vborg.vbsupport.ru/showthread.php?t=64059)

TouchingVirus 04-18-2004 03:56 PM

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?

assassingod 04-18-2004 04:01 PM

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') . '";');
    } 


TouchingVirus 04-18-2004 04:08 PM

Quick response, thanks for that Assassingod, i will try it straight away!

assassingod 04-18-2004 04:08 PM

No problem.

TouchingVirus 04-18-2004 04:10 PM

Works like a charm (not that i doubted :D) Thanks so much assassingod ;)

assassingod 04-18-2004 04:15 PM

Quote:

Originally Posted by assassingod
No problem.

;)

TouchingVirus 04-18-2004 04:27 PM

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

assassingod 04-18-2004 04:30 PM

Why use 2 templates instead of one? (Unless i've missed something)

TouchingVirus 04-18-2004 04:44 PM

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>


TouchingVirus 04-19-2004 05:56 PM

any ideas Assassingod


All times are GMT. The time now is 07:19 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.03906 seconds
  • Memory Usage 1,753KB
  • 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
  • (3)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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