FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Help needed





andyd34
I have the following code which draws a graph

Code:

include('../config/global.php'); // file which holds connection string

$maxHeight = $fetch($query('SELECT hits FROM propHits ORDER BY hits DESC'));
$qt=mysql_query('SELECT * FROM propHits WHERE propId = "$propId"');


header ("Content-type: image/jpg");


$x_gap=63; // The gap between each point in y axis

$x_max=$x_gap*12; // Maximum width of the graph or horizontal axis
$y_max=$maxHeight['hits']+60; // Maximum hight of the graph or vertical axis
// Above two variables will be used to create a canvas of the image//


$im = imagecreate ($x_max, $y_max)
or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($im, 245, 245, 220);
$text_color = imagecolorallocate ($im, 0, 0, 0);
$graph_color = imagecolorallocate ($im, 0, 0, 0);


$x1=0;
$y1=0;
$first_one="yes";
while($nt=mysql_fetch_array($qt)){
// echo $nt['month'].', '.$nt['hits'];
$x2=$x1+$x_gap; // Shifting in X axis
$y2=$y_max-$nt['hits']; // Coordinate of Y axis
imagestring($im,2,$x2,$y2-60,round($nt['hits']),$graph_color);
imagestring($im,2,$x2,$y_max-15,$nt['month'],$graph_color);
//Line above is to print month names on the graph
if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0
imageline ($im,$x1, $y1-40,$x2,$y2-40,$text_color); // Drawing the line between two points
}
$x1=$x2; // Storing the value for next draw
$y1=$y2;
$first_one="no"; // Now flag is set to allow the drawing
}

imagejpeg ($im);


The problem i am having is its not picking up WHERE id = '$propId' because it being included as an image

Code:
<img src = 'source.php' />


Does anyone know a way araound this[/code]
rvec
instead of
Code:
'SELECT * FROM propHits WHERE propId = "$propId"'


try this:
Code:
'SELECT * FROM propHits WHERE propId = \''. $propId .'\''
andyd34
Thanks for your reply

if i ad



Code:
$qt=mysql_query('SELECT * FROM propHits WHERE propId = "00004"');


instead of

Code:
$qt=mysql_query('SELECT * FROM propHits WHERE propId = "$propId"');


it will work fine so this isn't the issue.

The problem is the way the page is included, with it been an image is not picking up the dynamic contents.

Code:
header ("Content-type: image/jpg");


Code:
<img src = 'source.php' />


if you do this

Code:
<? include('source.php'); ?>


It just produces a load of code, its basically the same as adding a capchta/turing code
rvec
andyd34 wrote:

Code:
$qt=mysql_query('SELECT * FROM propHits WHERE propId = "00004"');


instead of

Code:
$qt=mysql_query('SELECT * FROM propHits WHERE propId = "$propId"');



The big difference between '' and "" is that everything between '' can't be a variable and everything between "" is checked for variables.

Code:
$a = 1;
echo '$a =1'; // will display $a =1
echo "$a = 1"; //will display 1 = 1


So the query you execute with the first code is SELECT * FROM propHits WHERE propId = "00004"
and the query you execute with the second query SELECT * FROM propHits WHERE propId = "$propId"
I don't think this is what you want, so try to use my code. This might not solve it all, but it will at least solve part of the problem.
andyd34
Thanks for your suggestion, i see what you mean about the syntax, what i should have done is copy and paste it from my script. here is what I have tried.

Code:
"SELECT * FROM propHits WHERE propId = '".$propId."'"


Code:
"SELECT * FROM propHits WHERE propId = '".$propId


Your Suggestion

Code:
'SELECT * FROM propHits WHERE propId = \''. $propId .'\''


But everything is still the same, I am going to try writing a cookie with the propId value and see if it will pick that up
andyd34
Look like that was the answer

Code:
"SELECT * FROM propHits WHERE propId = '".$_COOKIE['Prop']."'"


Working fine now
rvec
I thought it was set in global.php but I guess you forgot to set $propId then.
andyd34
The prob id is set via the login details from another page. The global.php holds the connection details
Related topics
Help Needed Regarding CGI And Php
Help needed to choose appropriate server.
Help needed from Noobie and other graphic artists.
Any thing suit for beginners better than FrontPage
Wordpess help needed.
phpBB - Installation Tutorial
Help needed
CSS Help needed : Table emulation with divs
A Bit Of Help Needed :P
how to slice images? help needed
Please help me!!!! HTML/Flash help needed!
Help needed link/page checker
php page-refresh/redirect/boot help needed please
Big Help needed .
No icons on backend??
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.