PDA

View Full Version : Another one..


TouchingVirus
04-18-2004, 03:56 PM
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..


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

$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
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..


$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


$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


// 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:

<td class="alt1" width="50%"]>$ip_from</td>
<td class="alt2" width="50%">$ip_to</td>


Country_Results template

$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