andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Incorporating in an existing site

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> User Quota
View previous topic :: View next topic  
Author Message
zzz
Newbie


Joined: 22 Aug 2003
Posts: 6

PostPosted: Fri Aug 22, 2003 12:45 pm    Post subject: Incorporating in an existing site Reply with quote

Hi,

And thatnks for the great scripts you've created. I'd like to try use you "User Quote script" in one of my projects. I tried to place a pie chart withing my page but keep getting the following error:

Warning: Cannot modify header information - headers already sent by (output started at.............. in ......../class.chart.php on line 307

Is there a work around this.

The second question: How difficult would it be using more then one slices in the pie. Would thgat requre major class rewrite?

Thanks.
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Aug 22, 2003 1:39 pm    Post subject: Reply with quote

Hi,

Welcome to the board!

The reason you're getting the error is because you have something outputting to the browser before the 'header' function is outputted. This can sometimes be text, but quite often it's just white space at the end of a file.

For example; image the text between the '---' lines to be in your file:

---
<?php

echo 'foo';

?>
---

Now what you want to make sure is that instead of that carriage return after the closing php tag, you want to have:

---
<?php

echo 'foo';

?>---

As for having extra figures... I'm sure it's possible. Haven't thought about how much extra work would be needed, but probably not a complete rewrite... All the code is in there, after all, but it would need a bit of tweaking, yeah. If you want a full blown graphing package, then there are classes out there that do this. The best one, I think, is jpgraph.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
zzz
Newbie


Joined: 22 Aug 2003
Posts: 6

PostPosted: Fri Aug 22, 2003 3:39 pm    Post subject: Reply with quote

There must be some output...

I put this script to a blank file and it works great, but when I put it on a page and this page is an include to a main mage that already has other include with the header, things start going wild.

In fact i'm reconsidering the use of the script. I have attempted successfully populate that chart with the data from my db and it looks great. Now I just need to to figure out how to add that chart to my existing page.
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Aug 22, 2003 4:04 pm    Post subject: Reply with quote

zzz wrote:
when I put it on a page and this page is an include to a main mage that already has other include with the header, things start going wild.


This is where you need to check then, the other include files. White space can come from anywhere, it doesn't matter. However, what you can do, which is similar to what I did is this:

In my main page which I want to have my image in, I have an image tag that looks like this:

PHP:
<?php

echo '<img src="showgraph.php?'$_SERVER['QUERY_STRING'], '">';

?>


I pass along the query string from a GET method, but you could always populate your query string with information from a database. In the query string I pass along the quota, the used size, and what colours I want. YOu could do something like this, for example:

PHP:
<?php

// set up your db connection and sql call here

$row mysql_query($sqlMYSQL_ASSOC);
echo 
'<img src="showgraph.php?quota='$row['quota'], '&used='$row['used'], '&width=250">';

?>


Then you have the showgraph.php file which, for me, looks like:

PHP:
<?php

    
require("class.userquota.php");
    
$uq = new userQuota($_GET['quota'], $_GET['used'], $_GET['username']);
    
$uq->setOutputImage();
    
$uq->setImageProperties($_GET['width'], ($_GET['op3D'] ? TRUE FALSE), ($_GET['opLegend'] ? TRUE FALSE), ($_GET['opCentre'] ? TRUE FALSE), $_GET['qColour'], $_GET['uColour'], $_GET['bColour'], $_GET['tColour']);
    
$uq->displayQuota();

?>


Obviously you can populate the parameters with whatever you pass, or hardcoded values, or a combination of both that works to get the results you want. So long as there's no additional whitespce at the start of that file it should all work correctly.

HTH.

Andy


Last edited by amnuts on Sat Aug 23, 2003 1:11 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
zzz
Newbie


Joined: 22 Aug 2003
Posts: 6

PostPosted: Fri Aug 22, 2003 4:42 pm    Post subject: Reply with quote

Got it! This was brilliant. It never dawned on me that I could echo image and use the php file as a source. Thanks for the detailed guidance.

I may go over the class and strip some of the code that I'm not going to be needing. I will hardcode the colors, size and positioning and will be feeding the data from the db, so I probably won't need all the luxury of the features. Any advice what I could safely remove? My pages are already heafty, so I'm looking for any excuse to rtim down a few bytes.

Perhaps sometime in the future you'll give it a thought to write a class that would do just that: allow multiple slices. I bet there are are a few out there that could definitely find use for a great script.

I'll be testing more, but the main headach is gone Smile

Thanks again.
Back to top
View user's profile Send private message
zzz
Newbie


Joined: 22 Aug 2003
Posts: 6

PostPosted: Sat Aug 23, 2003 10:54 am    Post subject: Reply with quote

Hi,

I ran into another set of problems, perhaps you have some ideas or workarounds. I have a file that generates a chart based on a data from my db, let's call it chart.php.

Then I have a main file that displays a data, main.php. This file displays a data based on the id I pass in URL. I include my chart like this:

echo "<img src=\"chart.php\">";

Because it is echoed into my main page, how do I get it to grab the data based on requested ID? I missed something in your suggestion, haven't I?

I also tried to include the chart like this:
Code:

$pie = $myvalue1;
$slice = $myvalue2;
echo "<img src='showgraph.php?pie=".$pie."&slice=".$slice."' align=right hspace=10>";


and used the following to get the parameters:
Code:
$uq = new userQuota($pie, $slice);
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Sat Aug 23, 2003 1:10 pm    Post subject: Reply with quote

Hi,

Okay, if I'm understanding this correctly you have two files. One file, let's call it index.php passes an id string within an <img> tag to another script, called chart.php which gets the user's information from a database based on the passed id string and then outputs the graph.

So on those assumptions your index.php file might look like this:

PHP:
<?php

echo '<p>Your quota graph</p>';
echo 
'<img src="chart.php?id='$_SESSION['userid'], '" align="right" hspace="10">';

?>


In that example I assume that the id string is in the $_SESSION variable 'userid'. Obviously you would pass it along by whatever means you have to get the id string.

Okay, so that's really all there is to index.php. Now you would have something like the following for chart.php.

PHP:
<?php

$dbcon 
= @mysql_connect('host''user''pass') or die("Unable to connect to mysql server: host");
@
mysql_select_db('mydb'$dbcon) or die("Unable to select database: mydb");

$result mysql_query("SELECT quota, used FROM quotas WHERE userid={$_GET['userid']}");
$row mysql_fetch_object($result);

require(
"class.userquota.php");
$uq = new userQuota($row->quota$row->used);
$uq->setOutputImage();
$uq->displayQuota(); 

?>


And there you go. You should have an image displayed now. What you can do, if you want to set particular colours, sizes, etc. for the quota then use the setImageProperties function before the displayQuota function. Such as having:

PHP:
<?php

// getting the quota here

require("class.userquota.php");
$uq = new userQuota($row->quota$row->used);
$uq->setOutputImage();
$uq->setImageProperties(50TRUETRUETRUE'DDDDDD''ED1C24''FFFFFF''55555'); 
$uq->displayQuota(); 

?>


Which sets the width to be 50, the graph to be 3D, the legend to be showing, the used wedge to be centred to the bottom of the graph (a la Windows quota), the quota colour to be 'DDDDDD', the wedge colour to be 'ED1C24', the image background to be 'FFFFFF', and the text colour to be '555555'.

See how that works out for ya.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
zzz
Newbie


Joined: 22 Aug 2003
Posts: 6

PostPosted: Sat Aug 23, 2003 8:46 pm    Post subject: Reply with quote

I got it!

Sorry for the confusion. The script worked the way I posted it last time. I don't know where my mind was, I forgot I renamed the file that had a code for generating the chart and was calling a non-existant file. Dah!

Thanks for all your help.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> User Quota All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group