wrx Posted January 31, 2010 Posted January 31, 2010 This could be used for any data you chose as (example chart users with most kills,rank,level,etc... have fun with it) the example below charts the stockmarket The following code will build a .gif or .png image of your stock market on the fly with the ability to call it when needed on any page. example image created from in game stockmarket to call the image in your page !! Yes your src image is "stockchart.php" You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. create file stockchart.php You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. i would reccomend using the first option to test for the GD library You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. once that is verified comment the above and use (edit this of course to pull your stock tables) You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. Any questions just ask ;) wrx Quote
wrx Posted January 31, 2010 Author Posted January 31, 2010 heres an example of the above code pointing at the user table Quote
BludClart Posted February 1, 2010 Posted February 1, 2010 hey mate,i have been looking for something like this for ages! But i have a problem =\ I want it to show stock performance over a duration of 2 hours,but cant get it working. What i want it to do is show the time(its in unix_timestamp) And how much it weant up/down at that time. This is what my stocks show already. Latest performance of this stock! 11 minutes ago: £0.043 ?</big> £4.0092 26 minutes ago: £0.058 ?</big> £4.0522 41 minutes ago: £0.051 ?</big> £4.1105 56 minutes ago: £0.035 ?</big> £4.1617 1 hours ago: £0.040 ?</big> £4.1971 1 hours ago: £0.055 ?</big> £4.2367 1 hours ago: £0.058 ?</big> £4.2915 1 hours ago: £0.037 ?</big> £4.3498 2 hours ago: £0.084 ?</big> £4.3756 2 hours ago: £0.103 ?</big> £4.4704 And this is what i have edited so far if it helps =\ You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. Quote
wrx Posted February 1, 2010 Author Posted February 1, 2010 hey mate,i have been looking for something like this for ages! But i have a problem =\ I want it to show stock performance over a duration of 2 hours,but cant get it working. What i want it to do is show the time(its in unix_timestamp) And how much it weant up/down at that time. This is what my stocks show already. Latest performance of this stock! 11 minutes ago: £0.043 ?</big> £4.0092 26 minutes ago: £0.058 ?</big> £4.0522 41 minutes ago: £0.051 ?</big> £4.1105 56 minutes ago: £0.035 ?</big> £4.1617 1 hours ago: £0.040 ?</big> £4.1971 1 hours ago: £0.055 ?</big> £4.2367 1 hours ago: £0.058 ?</big> £4.2915 1 hours ago: £0.037 ?</big> £4.3498 2 hours ago: £0.084 ?</big> £4.3756 2 hours ago: £0.103 ?</big> £4.4704 And this is what i have edited so far if it helps =\ You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. your data connection is commented out. you should be able to chart your trend if your storing in in the databse x=tickTIME y= stockPRICE did you get any image generated at all ? Quote
Uridium Posted February 1, 2010 Posted February 1, 2010 Nicely done and i would have thought this might have been in the paid mods section nice to see it for Free though.. Excellent work WRX Quote
4thdesign Posted February 1, 2010 Posted February 1, 2010 Guys....sorry, but you will have to forgive me for being a real noob when it comes to coding, but....i had a go here: (i want to pull the data out of the users table to show a graph of users names and the money they have) You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. But the image doesnt show,.....any ideas? ps....if i browse to stockchart.php, i have a bunch of code coming up which is showing lots of errors, but the first error, indicates the following: Warning: include(mysql.php) [function.include]: failed to open stream: No such file or directory in /home/mydomain/public_html/game/stockchart.php on line 7 and line 7 in the stockchart.php file is: include "mysql.php"; Any ideas whats gone wrong here? Quote
Uridium Posted February 1, 2010 Posted February 1, 2010 $q=mysql_query("SELECT * FROM users ORDER BY username ASC LIMIT 6",$c); try $q=mysql_query("SELECT username, money FROM users ORDER BY username ASC LIMIT 6",$c); Quote
4thdesign Posted February 1, 2010 Posted February 1, 2010 Thanks but....still not showing the image :( Quote
Uridium Posted February 1, 2010 Posted February 1, 2010 in your stock chart change include "mysql.php"; to include "config.php"; as mysql is for V1 and Config for V2 Quote
4thdesign Posted February 1, 2010 Posted February 1, 2010 hmmmm.....basic error, was looking at that and wondering where mysql.php file was !!! Ok....changed it, still didnt work, reverted back to using $q=mysql_query("SELECT * FROM users ORDER BY username ASC LIMIT 6",$c); in stockchart.php and i still cant see an image, and on looking at stockchart.php in the browser, it still shows up the same errors as before There is no reason for it not to connect to the database, everything else is working, so its connecting, but this stockchart.php file is wrong somewhere, but not sure why? Quote
wrx Posted February 1, 2010 Author Posted February 1, 2010 Nicely done and i would have thought this might have been in the paid mods section nice to see it for Free though.. Excellent work WRX ty sir , just offering something hopefully usefull to the community 8) in your stock chart change include "mysql.php"; to include "config.php"; as mysql is for V1 and Config for V2 I agree that looks like the problem.... also if you are having problems creating images simply run it with the db connections commented out to make sure your install will support the code Most Do but still an easy way to troubleshoot the GD functions of the code ============================================================ You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. reference top post for more detail on this.. hope this helps Quote
4thdesign Posted February 1, 2010 Posted February 1, 2010 Tested GD library, works fine :) Just copied the file again, made the changes and stockchart.php when using the browser, shows this error Warning: Wrong parameter count for max() in /home/mydomain/public_html/game/stockchart.php on line 39 which is this on line 39 $maxval = max($data); Which parameter is wrong? ;( Quote
Uridium Posted February 1, 2010 Posted February 1, 2010 4thdesign silly question but are you testing this on localhost or on your website as GD cant be used on localhost However if the file cannot call for config.php then you will need to help it along the way.. Example on your stockchart.php remove include "config.php"; and replace with session_start(); $config = DIRNAME(__FILE__) . '/config.php'; if(file_exists($config)) { include_once($config); } else { die("The game is being updated, please check back in a few seconds"); } define('MONO_ON', 1); $class_mysql = DIRNAME(__FILE__) . '/class/class_db_mysql.php'; if(file_exists($class_mysql)) { include_once($class_mysql); } else { die("The game is being updated, please check back in a few seconds"); } $db = new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c = $db->connection_id; $q=mysql_query("SELECT * FROM users ORDER BY username ASC LIMIT 6",$c); $strData = '$data=array('; While ($r=mysql_fetch_array($q)) { $strData .= "\"" . $r['username'] . "\"" . ' => ' . $r['money'] . ','; } $strData .= ');'; eval($strData); global $db, $ir, $c; Quote
wrx Posted February 1, 2010 Author Posted February 1, 2010 your trying to pull x=username table and y=money table ? try username table and userID just to verify ... my guess would be that the money might be a large amount and is throwing this value off ... ill try this myself with the user money table shortly Quote
4thdesign Posted February 1, 2010 Posted February 1, 2010 Yes, am testing this on the server. Just replaced the coding as suggested, still no image and still getting the error Warning: Wrong parameter count for max() in /home/mydomain/public_html/game/stockchart.php on line 39 although its line 55 now due to the extra code. Off to bed chaps, thanks for helping, will start from scratch tomorrow using all your advices that have been posted. Perhaps i have done something extremely silly in my tiredness! Thanks guys :) Quote
wrx Posted February 1, 2010 Author Posted February 1, 2010 tried to duplicate your error but was unable :( pointed it at my users money table here's my result and query info You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. sleep allways helps ;) Quote
Zero-Affect Posted February 2, 2010 Posted February 2, 2010 i only just started using GD for stuff so this will help ty WRX Quote
wrx Posted February 28, 2010 Author Posted February 28, 2010 Just got around to actually putting this in my news page.This page is completly dynamic and updates from 3 sources (news blog,wiki,db) to give current info to users. in game stock graph ( uses same code as origionally posted above) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.