Seperate number into 3 different bits...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Seperate number into 3 different bits...

Post by Dale »

Im pulling information from peoples sites (with their permission obviously) using a file (which they put in their main forum directory), the file is called hum.php.

hum.php :: Code View

Code: Select all

<?php

// Default Forum Stuff - Start
require "./global.php";
$stats = $cache->read("stats");
// Default Forum Stuff - End

$dalehay_posts = $stats&#1111;'numposts'];
$dalehay_threads = $stats&#1111;'numthreads'];
$dalehay_members = $stats&#1111;'numusers'];

echo $dalehay_posts;
echo $dalehay_threads;
echo $dalehay_members;

?>
In another file called mybbtrack.php i have placed some code which i want to update the database with there new updated forum stats via a image created with IMAGEPNG().

mybbtrack.php :: Code View

Code: Select all

<?php
$conn = mysql_connect("localhost","USERNAME","PASSWORD");
mysql_select_db("dframe_dale",$conn);

$sql = "SELECT * FROM top_mybb_sites WHERE id = '$trackid'";
	$result = mysql_query($sql,$conn) or die(mysql_error());
	while ($r = mysql_fetch_array($result)) &#123;
		$t_id = $r&#1111;'id'];
		$t_forumurl = $r&#1111;'forumurl'];
&#125;

$stats&#1111;'url'] = "$t_forumurl";
$lines = @file("".$stats&#1111;'url']."hum.php"); 
if(!$lines) &#123;
if(!$stats&#1111;'posts'] || !$stats&#1111;'threads'] || !$stats&#1111;'members']) &#123;
echo "<td colspan="3">Stat File Does not exist.</td>";
&#125;
&#125; else &#123;
foreach ($lines as $line_num => $line) &#123; 
echo $line;
&#125;
$html = implode('', $lines);
&#125;
?>
No at the moment that shows 702016 which means 70 posts in 20 threads with 16 members. However i want to know how I can get it to update the database everytime someone accesses the file (AND get the image to get chopped into its 3 sections.)

I hope that wasn't too mind boggling...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you could for example use the | to separate the values...

Code: Select all

echo implode("|", array($var1, $var2, ...));
and then in your retrieval code

Code: Select all

$items = explode("|", $pagecontents);


if the values become more complex, you might want to consider xml or whatever to wrap them up..
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Sounds really stupid of me, but i dont have the foggiest about arrays.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

all you need to know is that you can use foreach to loop over the items of them http://www.php.net/foreach for samples and more info

and with array($var1, $var2, ...) you create a new array with the elements $var1, $var2, ... That is because implode expects an array as 2nd parameter...

happy reading :P
Post Reply