Barand Posted August 5, 2008 Share Posted August 5, 2008 How are you passing the months and values to the graph? Quote Link to comment Share on other sites More sharing options...
rilana Posted August 5, 2008 Author Share Posted August 5, 2008 $x1=$originx-$x_gap; $y1=$originy; $first_one="yes"; while($nt=mysql_fetch_array($qt)){ //echo "$nt[month], $nt[sales]"; $x2=$x1+$x_gap; // Shifting in X axis $y2=$y_max-$nt[miv_wert]; // Coordinate of Y axis $datum= date("F", strtotime($nt['miv_datum'])); imagettftext($im,8,90,$x2+5,$y0+295,$graph_color,$font,$datum); //Line above is to print month names on the graph if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0 imagesetthickness ($im,$th); imageline ($im,$x1, $y1,$x2,$y2,$text_colorMiv); // Drawing the line between two points imageline ($im,0,560,300,560,$grid_color); } $x1=$x2; // Storing the value for next draw $y1=$y2; $first_one="no"; // Now flag is set to allow the drawing } Quote Link to comment Share on other sites More sharing options...
Barand Posted August 5, 2008 Share Posted August 5, 2008 try $x1=$originx-$x_gap; $y1=$originy; $first_one="yes"; $prevDatum = ''; while($nt=mysql_fetch_array($qt)){   //echo "$nt[month], $nt[sales]";   $x2=$x1+$x_gap; // Shifting in X axis   $y2=$y_max-$nt[miv_wert]; // Coordinate of Y axis   $datum = date("F", strtotime($nt['miv_datum']));     $month = $datum==$prevDatum ? '' : $datum;             // check for same month name   $prevDatum = $datum;     imagettftext($im,8,90,$x2+5,$y0+295,$graph_color,$font,$month);   //Line above is to print month names on the graph   if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0   imagesetthickness ($im,$th);   imageline ($im,$x1, $y1,$x2,$y2,$text_colorMiv); // Drawing the line between two points   imageline ($im,0,560,300,560,$grid_color);   }   $x1=$x2; // Storing the value for next draw   $y1=$y2;   $first_one="no"; // Now flag is set to allow the drawing } Quote Link to comment Share on other sites More sharing options...
rilana Posted August 5, 2008 Author Share Posted August 5, 2008 yes that works perfect. I dont understand what $month = $datum==$prevDatum ? '' : $datum; this means. month is datum does it equal prevDatum '' divided by datum??? Where do I learn syntax like this so it makes sens to me? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 5, 2008 Share Posted August 5, 2008 it's called "ternary" if you want to look it up.   $var = <condition> ? <value if condition true> : <value if condition false>;  Short for  if ($datum == $prevDatum)     // is datum same as previous datum {   $month = '';             // if it is, print '' instead of repeating the month } else {   $month = $datum;        // it's different so print new value } Quote Link to comment Share on other sites More sharing options...
rilana Posted August 7, 2008 Author Share Posted August 7, 2008 ternary was interesting... I have to keep it in mind! I read the tutorial in the front about handling database. It's a tutorial on how to set up a script that allows you to add, edit and delet all in the same script. I am still working on the backend of this thing, and it was easy to set up a form that enters values to the database. But now I am stuck. The tutorial helped me understand a lot, but now that I am trying to change it to my needs, I am having problems. In the end of the script there is a form echo <<<NEWENTRY  <tr>    <td bgcolor = 'gray'></td>    <td><input type = 'text' miv_datum = 'miv_datum'></td>     <td><input type = 'text' miv_wert = 'miv_wert'></td>    <td bgcolor = 'gray'></td>  </tr><tr>    <td></td>    <td align = 'center'><input type = 'submit' value = 'submit'></td>    <td></td>  </tr> </table> </form> Somehow this submit button is suposed to send the input text value to the post function. // INSERT: if we have a name to add... if($_POST['miv_datum']['miv_wert']) {  // little bit of cleaning...  $miv_datum = mysql_real_escape_string($_POST['miv_datum']);  $miv_wert = mysql_real_escape_string($_POST['miv_wert']);  // insert new name into table  $sql = "INSERT INTO miv (ID, miv_datum, miv_wert) VALUES ('','$miv_datum','miv_wert')";  $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); } Now the tutorial was only with one text-field in the form, so maby I am doing something wrong by adding more values. Am I supused to make a string or something like that? I tryed different things out, but it's not working. Thank's for helping. Rilana Quote Link to comment Share on other sites More sharing options...
Barand Posted August 7, 2008 Share Posted August 7, 2008 what's your form tag? Quote Link to comment Share on other sites More sharing options...
rilana Posted August 7, 2008 Author Share Posted August 7, 2008 I am not shoure do you meen this? Â echo <<<LISTCOLS <form action = '{$_SERVER['PHP_SELF']}' method = 'post'> <table border = '1'> Â <tr> Â Â Â <td><a href = '{$_SERVER['PHP_SELF']}?orderby=ID'>id</td> Â Â Â <td><a href = '{$_SERVER['PHP_SELF']}?orderby=miv_datum'>miv_datum</td> Â <td><a href = '{$_SERVER['PHP_SELF']}?orderby=miv_wert'>miv_wert</td> Â Â Â <td>delete</td> Â </tr> LISTCOLS; Quote Link to comment Share on other sites More sharing options...
Barand Posted August 7, 2008 Share Posted August 7, 2008 inputs need to be  <td><input type = 'text' name = 'miv_datum'></td>     <td><input type = 'text' name = 'miv_wert'></td>   and to see if data sent if($_POST['miv_datum'])  Quote Link to comment Share on other sites More sharing options...
rilana Posted August 13, 2008 Author Share Posted August 13, 2008 Hi, sorry for taking so long. Thank you verry much I am almost done now. I just have one last thing to worry about. After one year the graph will be to wide to continue. I could be deleting entrys from the database, but it would be much cooler if I could say something like: if id == 52 show no more then 52 entrys, for example if there are 53 entrys, show id 2 till 53... But I dont realy know how to set this up. I probably have to change the whole coding arround.... Can you give me a hint? here is the part that need to be changed  $x1=$originx-$x_gap; $y1=$originy; $first_one="yes"; while($nt=mysql_fetch_array($qt)){ //echo "$nt[month], $nt[sales]"; $x2=$x1+$x_gap; // Shifting in X axis $y2=$y_max-$nt[miv_wert]; // Coordinate of Y axis $datum= date("d.m.y", strtotime($nt['miv_datum']));   imagettftext($im,8,90,$x2+5,$y0+295,$graph_color,$font,$datum); //Line above is to print month names on the graph if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0 imagesetthickness ($im,$th); imageline ($im,$x1, $y1,$x2,$y2,$text_colorMiv); // Drawing the line between two points imageline ($im,0,560,300,560,$grid_color); } $x1=$x2; // Storing the value for next draw $y1=$y2; $first_one="no"; // Now flag is set to allow the drawing }  thank you Quote Link to comment Share on other sites More sharing options...
Barand Posted August 13, 2008 Share Posted August 13, 2008 Change it back at the query where you sect the data and use LIMIT x,y in your SQL, where x is the record to start at and y is the number of records to retrieve. Â Get a count of the records, then "... ORDER BY date LIMIT (count-52), 52" so you always get the last 52 records on the file. Quote Link to comment Share on other sites More sharing options...
rilana Posted August 14, 2008 Author Share Posted August 14, 2008 Hi, thank you so much for your feedback. I tryed several things, but I am doing something wrong. this works... Â $qt=mysql_query("select * from miv LIMIT 0, 10"); Â But as soon as I try to do this: $qt=mysql_query("select * from miv ORDER BY miv_datum LIMIT (count-52), 52"); Â the output is empty, what am I doing wrong? thank you, Rilana Quote Link to comment Share on other sites More sharing options...
Barand Posted August 14, 2008 Share Posted August 14, 2008 you need to get the count first. Â $res = mysql_query ("SELECT COUNT(*) FROM miv"); $count = mysql_result($res, 0); if ($count < 52) $count = 52; $qt=mysql_query("select * from miv ORDER BY miv_datum LIMIT ($count-52), 52"); Quote Link to comment Share on other sites More sharing options...
rilana Posted August 14, 2008 Author Share Posted August 14, 2008 ok sorry, I dont get it. It's not working. Â $res = mysql_query ("SELECT COUNT(*) FROM miv"); $count = mysql_result($res, 0); if ($count < 52) $count = 52; $qt=mysql_query("select * from miv ORDER BY miv_datum LIMIT ($count-52), 52"); header ("Content-type: image/jpg"); Â Maby the mysql_fetch_array($qt) does not work this way anymore, could that be a possibility? Â $x1=$originx-$x_gap; $y1=$originy; $first_one="yes"; while($nt=mysql_fetch_array($qt)){ //echo "$nt[month], $nt[sales]"; $x2=$x1+$x_gap; // Shifting in X axis $y2=$y_max-$nt[miv_wert]; // Coordinate of Y axis $datum= date("d.m.y", strtotime($nt['miv_datum'])); Quote Link to comment Share on other sites More sharing options...
rilana Posted August 20, 2008 Author Share Posted August 20, 2008 I just wanted to say thank you so much for everything, i just have this last Problem and I probably will figure it out later... Thanks' I realy aprechiate your help! could not have done it without you. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 20, 2008 Share Posted August 20, 2008 have you tried  $qt=mysql_query("select * from miv ORDER BY miv_datum LIMIT ($count-52), 52") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Barand Posted August 20, 2008 Share Posted August 20, 2008 I just did a quick test. You need to precalculate the start position. Â $start = $count-52; $qt=mysql_query("select * from miv ORDER BY miv_datum LIMIT $start, 52"); Quote Link to comment Share on other sites More sharing options...
rilana Posted August 20, 2008 Author Share Posted August 20, 2008 Wow thanks a lot! that last one worked!!! cool! thank you Quote Link to comment Share on other sites More sharing options...
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.