Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Everything posted by Nodral

  1. Sorted it. Sorry to have bothered you
  2. Hi all Please see function below. the error I get is and I've no idea why. I've highlighted line 97, rather than put all prior functions in too. <?php function drawGraph($ed, $y2007, $y2008, $y2009, $y2010, $y2011, $name){ //Create image size and initiate $image=imagecreate(750,700); //define colours $background=imagecolorallocate($image, 255, 255, 255); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); $red = imagecolorallocate($image, 255, 0, 0); $blue = imagecolorallocate($image, 0, 51, 204); $green = imagecolorallocate($image, 0, 204, 255); $pink = imagecolorallocate($image, 204, 0, 255); $brown = imagecolorallocate($image, 153, 51, 0); //draw axes imageline($image, 0, 600, 650, 600, $black); imageline($image, 100, 10, 100, 700, $black); //calculate top coordinates $y2007a=600-($y2007*50); $y2008a=600-($y2008*50); $y2009a=600-($y2009*50); $y2010a=600-($y2010*50); $y2011a=600-($y2011*50); //draw recantgles imagefilledrectangle($image,110,600,210,$y2007a, $red); imagefilledrectangle($image,210,600,310,$y2008a, $blue); imagefilledrectangle($image,310,600,410,$y2009a, $green); imagefilledrectangle($image,410,600,510,$y2010a, $pink); imagefilledrectangle($image,510,600,610,$y2011a, $brown); //add x labels imagefttext($image, 18, 0, 140,650, $black, 'arial.ttf', "2007"); imagefttext($image, 18, 0, 240,650, $black, 'arial.ttf', "2008"); imagefttext($image, 18, 0, 340,650, $black, 'arial.ttf', "2009"); imagefttext($image, 18, 0, 440,650, $black, 'arial.ttf', "2010"); imagefttext($image, 18, 0, 540,650, $black, 'arial.ttf', "2011"); //add values imagefttext($image, 18, 0, 160, $y2007a-50, $black, 'arial.ttf', "$y2007"); imagefttext($image, 18, 0, 260, $y2008a-50, $black, 'arial.ttf', "$y2008"); imagefttext($image, 18, 0, 360, $y2009a-50, $black, 'arial.ttf', "$y2009"); imagefttext($image, 18, 0, 460, $y2010a-50, $black, 'arial.ttf', "$y2010"); imagefttext($image, 18, 0, 560, $y2011a-50, $black, 'arial.ttf', "$y2011"); //add title imagefttext($image, 15, 0, 130,25, $black, 'arial.ttf', "Courses Attended per year for $name 2007 to 2011"); //produce image $filename = "$ed.jpg"; imagejpeg($image, $filename); //save to TEMP TABLE //read file $fp = fopen($filename,'r'); $data = fread($fp, filesize($filename)); $data = addslashes($data); //insert into table $sql = "INSERT INTO graphs (ed, image) VALUES ( $ed, '$data')"; mysql_query($sql); //delete file from server //line 97 $fclose("$filename"); unlink($filename); imagedestroy($image); }
  3. Hi All I've got a DB with approx 3 thousand users and a weekly graph is created using php for each users usage. This is processed by a cron job. The issue I have is storing the graph images. I've googled the situation and I'm getting a large difference of opinions about which is the best way to do it. almost a 50 / 50 split Blobs or files. I'd like to do it as blobs as I have issues with file permissions on my hosting server (ie I can write an image file, but then if it needs overwriting or deleting I can't do it dynamically, even when I set the file permissions to 777) My question is, how do I insert an image into a DB? If for example my image was user1.jpg, what would the process be from a SQL statement?
  4. Sorry guys, been a long day (and getting longer!!) Now, same table, why doesn't this work? SELECT coursename, DATE_FORMAT('startdate', %D, %M, %Y) as start FROM courses WHERE ed = 429 AND startdate > '2007-01-01' ORDER BY startdate
  5. Hi All Any ideas what is wrong with this query? SELECT count(*) as number WHERE ed = 429 AND YEAR(StartDate) = '2007' Data is as below ID ED CourseName StartDate 1405 429 In Search of Promoters 2011-02-01 10:00:00 1406 429 Managing the Customer Experience 2011-02-15 09:30:00 1407 635 Driver Awareness 2009-12-08 09:00:00 1408 635 Time Management 2007-03-23 10:00:00 1409 635 Fleet Administration 2005-04-13 10:00:00 1410 635 Coaching and Counselling Skills 2004-04-06 10:00:00 Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ed = 429 AND YEAR(StartDate) = '2007'' at line 1
  6. Hi I am running a query which should only pull back the year from my DB table, however I am getting a list of null results My query is SELECT YEAR('Date') as year FROM courses and my data is ID EMPNO Coursename Date 1389 429 NFR Returns 2007-06-12 10:00:00 1390 429 Age Discrimination Conference Call 2006-09-13 14:00:00 1391 429 HOME Getting More Out Of Your Day 2007-09-07 09:30:00 1392 429 Pivotal Launch 2005-04-21 10:00:00 1393 429 Coaching for Improved Performance 2005-05-25 09:30:00 ANy ideas? I only need to return the date from this Date is set as a DateTime data type
  7. Your syntax is out. This line should be somehting like while ($row = mysql_fetch_array($results){ //do somehting with each returned result as $row['xx'] }
  8. You need to be slightly clearer on what you want. There is an AVG function within MYSQL which will do what you want and you can still have a WHERE clause on it. Eg SELECT AVG(Result_overall_percentage) as Average FROM Results WHERE ........................ This will give you a return called 'Average' depending on the conditions you specify in the WHERE clause
  9. Do you have a unique numbered column in your DB table? If so, you could return all entries from this column into an array, pick 6 random numbers from the array, the call the pictures from the DB ie $sql="SELECT id FROM images"; $sql=mysql_query($sql); while($row=mysql_fetch_array($sql){ $references[]=$row[id]; } $random=array_rand($references,6); foreach ($random as $value){ $sql="SELECT image, link FROM images WHERE id = $value"; $sql=mysql_query($sql); $image=mysql_fetch_array($sql); echo "<a href='". $image['link'] ."'><img src='".$image['image']."'/></a>"; }
  10. What code have you got so far or do you want to pay someone to write the whole thing for you?
  11. strlen() test the number of charachters in the returned value. If it is not empty, the length will be greater than 0. If it is empty, the length will be 0, and therefore you set the value of the variable to be "Empty"
  12. The way I tend to do this is even more straight forward. if(strlen($row) <1) { $row = "Empty" } Simples!!
  13. Any code for us to look at? Sounds like you've got a bit of Javascript working on an onClick or onSubmit action
  14. Hi All I've a question regarding php and mysql database interrogation. Is there a way of applying a scalar database call from php, rather than having to return values in an array? For example if I know there is only 1 value in a DB table which matches a select statement, do I have to return it with the following or is there another function which will save me using arrays? $sql="SELECT name FROM users WHERE id = 10"; $sql=mysql_query($sql); $row=mysql_fetch_array($sql); This would then give me $row['name'] to work with. Is there a way of doing this?
  15. Nobody is going to go through all your code without you being more specific. Are you getting an error? What do you want it to do? What is it actually doing? Which line numbers are causing issues? etc etc.....
  16. Hi You can use a simple For loop for this. // Generate a random name for the file and move it for($i=1, $i>=6, $i++){ $newname = substr(md5(microtime()), 0, 12) . $extension; $copied = move_uploaded_file($file['tmp_name'], UPLOAD_DIRECTORY . DIRECTORY_SEPARATOR . $newname.$i); }
  17. Your error indicates that $total is not a valid SQL result. Check your column titles etc and ensure you are actually getting some information coming back out of the query
  18. You could embed two For loops to acheive this <table> <?php for ($a=1; $a<=9; $a++){ echo "<tr>"; for ($b=1; $b<=9; $b++){ echo "<td>$a * $b = ".$a*$b."</td>"; } echo "</tr>"; } ?> </table>
  19. Read this http://php.net/manual/en/function.fopen.php
  20. Can you post all code around the given line so we can see where the error may be
  21. Try opening the file with $fp = fopen('logfile.txt', 'r'); This will enable you to read the file rather than append it
  22. Ok, so now I have this... <?php function getLatLong($address){ if (!is_string($address))die("All Addresses must be passed as a string"); $_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address)); $_result = false; if($_result = file_get_contents($_url)) { if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false; preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!U', $_result, $_match); $_coords['lat'] = $_match[1]; $_coords['long'] = $_match[2]; } return $_coords; } $address="high+street+leicester+england"; $output=getLatLong($address); foreach($output as $value){ echo $value."<br>"; } and I get this error I understand the Foreach error, any ideas how I can sort this lat & long issue?
  23. Use something like if(strlen($_POST['variablename'])>1{ echo $_POST['variablename']; } else { echo "result from DB"; } This way if they have entered something on the form, it will POST it back to the form when they reload the page, if nothing has been POSTed, then it will put the data from the DB in there.
  24. Hi All I've a huge database of addresses and I need to convert them to Latitude and Longtitude to enable me to do some geopositioning and distances etc. I've tried the following code, but just get a blank result <?php $address="high+street+leicester+england"; $url = 'http://maps.google.com/maps/geo?q='.$address.'&output=json&oe=utf8&sensor=false&key='.$api_key; $data = @file_get_contents($url); $jsondata = json_decode($data,true); if(is_array($jsondata )&& $jsondata ['Status']['code']==200){ $lat = $jsondata ['Placemark'][0]['Point']['coordinates'][0]; $lon = $jsondata ['Placemark'][0]['Point']['coordinates'][1]; } echo "hello".$lat . " " . $lon; in my php.ini ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. allow_url_fopen = On ; Whether to allow include/require to open URLs (like http:// or ftp://) as files. allow_url_include = On Any ideas?
  25. Hi all I'm trying to create an XML file to be used within Excel. The data is drawn dynamically from my database depending on the information supplied by the user. However when I run it, I get a complain from Excel about some missing whitespace. any ideas? <?php $output='<?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Author>Europcar</Author> <LastAuthor>Europcar</LastAuthor> <Created>2011-10-28T10:48:37Z</Created> <Company>Europcar</Company> <Version>11.9999</Version> </DocumentProperties> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>11760</WindowHeight> <WindowWidth>15195</WindowWidth> <WindowTopX>480</WindowTopX> <WindowTopY>75</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Bottom"/> <Borders/> <Font/> <Interior/> <NumberFormat/> <Protection/> </Style> </Styles> <Worksheet ss:Name="Sheet1"> <Table ss:ExpandedColumnCount="'.$columns.'" ss:ExpandedRowCount="'.($count+5).'" x:FullColumns="1"x:FullRows="1">'; //$output.='<Column ss:AutoFitWidth="0" ss:Width="50"/>/n'; $output.='<Row>'; foreach ($titles as $value){ if(is_numeric(substr($value,0,1))){ $value=substr($value,1); } $output.='<Cell><Data ss:Type="String">'.$value.'</Data></Cell>'."LF"; } /*$output.='</Row>'; foreach ($dataOut as $value){ $output.='<Row>'; foreach($value as $values){ if(strlen($values)<1){ $values=" "; } $output.= '<Cell><Data ss:Type="String">'.$values.'</Data></Cell>'; } $output.='</Row>'; }*/ $output.=' </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <Selected/> <Panes> <Pane> <Number>3</Number> <ActiveRow>'.($count+5).'</ActiveRow> <ActiveCol>'.$columns.'</ActiveCol> </Pane> </Panes> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> </Workbook>';
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.