Jump to content

GalaxyTramp

Members
  • Posts

    59
  • Joined

  • Last visited

Everything posted by GalaxyTramp

  1. I think I am correct in saying that $server is a GLOBAL so you cannot use it in this way. GT
  2. take a look here http://dev.mysql.com/doc/refman/5.0/en/join.html
  3. Is there any reason not to use links such as: <a href='/results.html?id=12&location[]=" . str_replace(' ', '+', $location). "</a> I refer to the empty square array brackets. Is this a bad/risky practise or quite acceptable? Your opinions please. GT
  4. I am using the following script on a couple of websites and it works well: <?php ////////////////////////////////////////////////////// THIS IS THE FUNCTION_RESIZE.PHP FILE /////////////////////////////////////////////////////////////////////////////////////// /* function by Wes Edling .. http://joedesigns.com feel free to use this in any project, i just ask for a credit in the source code. a link back to my site would be nice too. */ function resize($imagePath,$opts=null){ # start configuration $cacheFolder = './cache/'; # path to your cache folder, must be writeable by web server $remoteFolder = $cacheFolder.'remote/'; # path to the folder you wish to download remote images into $quality = 90; # image quality to use for ImageMagick (0 - 100) $cache_http_minutes = 20; # cache downloaded http images 20 minutes $path_to_convert = '/usr/bin/convert'; ## you shouldn't need to configure anything else beyond this point $purl = parse_url($imagePath); $finfo = pathinfo($imagePath); $ext = $finfo['extension']; # check for remote image.. if(isset($purl['scheme']) && $purl['scheme'] == 'http'): # grab the image, and cache it so we have something to work with.. list($filename) = explode('?',$finfo['basename']); $local_filepath = $remoteFolder.$filename; $download_image = true; if(file_exists($local_filepath)): if(filemtime($local_filepath) < strtotime('+'.$cache_http_minutes.' minutes')): $download_image = false; endif; endif; if($download_image == true): $img = file_get_contents($imagePath); file_put_contents($local_filepath,$img); endif; $imagePath = $local_filepath; endif; if(file_exists($imagePath) == false): $imagePath = $_SERVER['DOCUMENT_ROOT'].$imagePath; if(file_exists($imagePath) == false): return 'image not found'; endif; endif; if(isset($opts['w'])): $w = $opts['w']; endif; if(isset($opts['h'])): $h = $opts['h']; endif; $filename = md5_file($imagePath); if(!empty($w) and !empty($h)): $newPath = $cacheFolder.$filename.'_w'.$w.'_h'.$h.(isset($opts['crop']) && $opts['crop'] == true ? "_cp" : "").(isset($opts['scale']) && $opts['scale'] == true ? "_sc" : "").'.'.$ext; elseif(!empty($w)): $newPath = $cacheFolder.$filename.'_w'.$w.'.'.$ext; elseif(!empty($h)): $newPath = $cacheFolder.$filename.'_h'.$h.'.'.$ext; else: return false; endif; $create = true; if(file_exists($newPath) == true): $create = false; $origFileTime = date("YmdHis",filemtime($imagePath)); $newFileTime = date("YmdHis",filemtime($newPath)); if($newFileTime < $origFileTime): $create = true; endif; endif; if($create == true): if(!empty($w) and !empty($h)): list($width,$height) = getimagesize($imagePath); $resize = $w; if($width > $height): $resize = $w; if(isset($opts['crop']) && $opts['crop'] == true): $resize = "x".$h; endif; else: $resize = "x".$h; if(isset($opts['crop']) && $opts['crop'] == true): $resize = $w; endif; endif; if(isset($opts['scale']) && $opts['scale'] == true): $cmd = $path_to_convert." ".$imagePath." -resize ".$resize." -quality ".$quality." ".$newPath; else: $cmd = $path_to_convert." ".$imagePath." -resize ".$resize." -size ".$w."x".$h." xc:".(isset($opts['canvas-color'])?$opts['canvas-color']:"transparent")." +swap -gravity center -composite -quality ".$quality." ".$newPath; endif; else: $cmd = $path_to_convert." ".$imagePath." -thumbnail ".(!empty($h) ? 'x':'').$w."".(isset($opts['maxOnly']) && $opts['maxOnly'] == true ? "\>" : "")." -quality ".$quality." ".$newPath; endif; $c = exec($cmd); endif; # return cache file path return str_replace($_SERVER['DOCUMENT_ROOT'],'',$newPath); } //////////////////////////////////////////////////////////////// THIS IS THE EXAMPLE.PHP FILE ////////////////////////////////////////////////////////////////////////////////////////////////////////// <?php # include the function here include 'function.resize.php'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>PHP Image Resize - Example</title> <style> body { background: #ffffff; color: #121212; font-family: lucida grande; text-align: center; } h1 { font-size: 15px; text-align: center; } #main { margin: auto; width: 600px; text-align: left; } .block { margin: 20px; background: #fafafa; padding: 20px; text-align: center; border: 1px solid #cacaca; } pre { text-align: left; background: #010101; padding: 10px; font-size: 11px; } pre code { text-align: left; color: #ffffff; } .block p { color: #343434; font-size: 12px; } </style> </head> <body> <div id='main'> <h1>PHP Image Resizer</h1> <div class='block'> <?php $settings = array('w'=>150,'h'=>150,'crop'=>true); ?> <div><img src='<?=resize('http://www.image-online.com/admin.jpg',$settings)?>' border='0' /></div> <p>Image cropped & resized by width and height from a remote location.</p> <div><pre><code>src: http://www.image-online.com/admin.jpg<?php echo "\n\n"; print_r($settings)?></code></pre></div> </div> </div> </body> </html> ?> I now need the script to be able to resize images created dynamically from URL's in the following format: http://www.image-online.com/ShowImage.asp?SecId=zc&Id=P1&ImgId=03073 Is there any way of accessing the image created at this URL in order that I can manipulate it with this or another script. Regards GT
  5. print your array to see what variables you are actually returning, if any.
  6. The error message implies that you have a problem with the field names in your query. Whatever "Blah Blah" is named as in your query is probably not named the same in your DB. I notice you are spelling adress with one 'd' in the query, is this the same fieldname in your DB?
  7. I know have another problem. When form is submitted without selecting a value for property I need it to return all results. The query prints like this: WHERE location IN ("") AND cat_id = '12' AND status = 'Yes' No results found. Code is now: $where = array(); if(!empty($_GET['cat_id'])) { // Allow only numeric characters $cat_id = preg_replace('/[^0-9 ]/', '', $_GET['cat_id']); $param = mysql_real_escape_string($cat_id); $where []= "cat_id = '$param'"; } if(!empty($_GET['location'])) { $param = preg_replace('/[^á é í ó ú ñ ü Á É Í Ó Ú Ü a-zA-Z0-9]/', '', $_GET['location']); $where[] = 'location IN ("' . implode('", "', $param) . '")'; } $where = (!empty($where)) ? ' WHERE ' . implode(' AND ', $where) : ''; $where []= "status = 'Yes'"; echo $where;
  8. Fixed! I had indeed forgotten to remove the for each loop Thanks for your time David much appreciated Regards C
  9. OK after some shut eye I have returned to this and added the implode as per the last post. This does actually produce a workable query but it is repeating itself due to the other implode further down the page that puts the final query together. I now have a query the prints as: WHERE location IN ("town1", "town2", "town3", "town4", "town5") AND location IN ("town1", "town2", "town3", "town4", "town5") AND location IN ("town1", "town2", "town3", "town4", "town5") AND location IN ("town1", "town2", "town3", "town4", "town5") AND location IN ("town1", "town2", "town3", "town4", "town5") AND cat_id = '12' AND status = 'Yes $where = (!empty($where)) ? ' WHERE ' . implode(' AND ', $where) : ''; // This is the culprit I need to stop the location IN looping AARGH!! Thanks
  10. Yes having taken a step back it is quite obvious that location cannot be "town1" AND "town2" at the same time. Time for a few hours off so I will digest your response tommorrow. The real script does sanitize with mysql_real_escape_string() Thanks
  11. I now have this query but it does not work, it returns an empty result!!: SELECT * FROM `property` WHERE location = 'town1' AND location = 'town2' AND cat_id = '12' AND status = 'Yes' id | location | status | price | ----------------------------------------------------- 12 | town1 | Yes | 200 | | | | | 12 | town2 | Yes | 400 | | | | | 12 | town3 | Yes | 600 | I am obviously missing the obvious here Thanks for looking
  12. OK sorted the Array problem after a rest. if(!empty($_GET['location'])) { // Allow only alphabetic and Spanish special characters $param = preg_replace('/[^á é í ó ú ñ ü Á É Í Ó Ú Ü a-zA-Z0-9]/', '', $_GET['location']); foreach ($param as $key => $value) { $where []= "location = '$value'"; } } Thanks
  13. It would seem that the id is not being set.
  14. Hi I am trying to put together the correct query for my DB but weariness is getting the better of me I think. I have a multiple list bow which posts info which I need to string together as a query. The relevant form part: $locationmenu = "<select name='location[]' size='10' multiple='multiple' style='width:180px'>\n\t<option value=\"\">Show All</option>\n\t"; $q1 = "SELECT DISTINCT `location` from `feed_property` WHERE status = 'Available' order by location"; $r1 = mysql_query($q1) or die(mysql_error()); if(mysql_num_rows($r1) > '0') { while($a1 = mysql_fetch_array($r1)) { $locationmenu .= "<option value=\"$a1[location]\">$a1[location]</option>\n\t"; } } $locationmenu .= "</select>\n"; and the part of the page where I am trying to construct the query: $where = array(); if(!empty($_GET['ref'])) { // Allow only alphanumeric characters $param = preg_replace('/[^a-zA-Z0-9]/', '', $_GET['ref']); $param = mysql_real_escape_string($param); $where[] = "propertyref = '$param'"; } if(!empty($_GET['location'])) { $param = preg_replace('/[^á é í ó ú ñ ü Á É Í Ó Ú Ü a-zA-Z0-9]/', '', $_GET['location']); foreach ($param as $location) { $where []= "location = '$param'"; //THIS IS THE PROBLEM LINE } } $where = (!empty($where)) ? ' WHERE ' . implode(' AND ', $where) : ''; echo $where; The $where prints as "WHERE location = 'Array' AND location = 'Array' AND location = 'Array' AND cat_id = '12' AND status = " I need to get the multiple location selections in where the 'Array' is returned. Almost there but then almost doesn't really cut it All help appreciated GT
  15. DOH!! Your code works perfectly thanks
  16. I am trying to delete records across 3 tables but my code does not work. $query = ("SELECT `propertyref` FROM `feed_property` WHERE `status` = 'Sold' ")or die(mysql_error()); $result = mysql_query($query); if (isset($result)) { while ($row = mysql_fetch_array($result)): $ref1 = mysql_real_escape_string($row['propertyref']); $query1 = ("DELETE FROM `feed_property`, `feed_images`, `feed_characteristics`\n" . "USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics`\n" . "WHERE feed_property.propertyref = '$ref1'\n" . " AND feed_images.propertyref = feed_property.propertyref\n" . " AND feed_characteristics.propertyref = feed_property.propertyref; ")or die(mysql_error()); echo $query1; endwhile; if(!mysql_query($query1)){ echo '<h1 style="color: red;">Error</h1><p>', mysql_error(), '</p>'; } else { echo '<h1 style="color: red;">Properties have been removed from the database</h1>'; } } Query1 echos as: DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc1' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc2' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; The query completes without errors but does not delete the entries in the DB. If I run the query singly in PHP My Admin it functions correctly. thanks for your help
  17. Ok this has been driving me crazy for days now. I need to update my DB with multiple data parsed from an XML feed. I need some help in putting together the query. Currently I have: $xml= 'test-feed.xml'; // URL for feed. try{ $feed = new SimpleXMLElement($xml, null, true); }catch(Exception $e){ echo $e->getMessage(); exit; } $sqlxml = ""; $arr = array(); foreach($feed->property as $property) { $propertyid = (string)$property->id; foreach($property->images->image as $image) { $i = 0; $url = (string)$image->url; $arr[] = "UPDATE property SET url = '$url' WHERE prop_id = '$propertyid', "; $i++; } } foreach($arr as $result) $sql .= $result; $sql = rtrim($sql, ","); echo $sql; if(!mysql_query($sql)){ echo '<h1 style="color: red;">Error</h1><p>', mysql_error(), '</p>'; } else { echo '<h1 style="color: red;">Property data successfully added to database!</h1>'; } This structures the query correctly for a single update but repeats it which then throws a MYSQL Syntax error. I am not sure of the correct syntax to use for multiple inserts?? What I get returned at the moment is: UPDATE property SET url = 'ImageId=X1000245' WHERE prop_id = 'A1234', UPDATE property SET url = 'ImageId=X1000296' WHERE prop_id = 'A1234', UPDATE property SET url = 'ImageId=P3&ImgId=X1000237' WHERE prop_id = 'ABC1234', Need some intervention guys Thanks in advance GT
  18. foreach ($xml->xml->undeveloped_lands->land as $value){ $id=$value->id; $cost=$value->cost; //do stuff here }
  19. Whoops! published the wrong XML SORRY Should read: <?xml version="1.0" encoding="UTF-8"?> <root> <property> <id>153</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Title 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Title 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Title 3</en> </title> </images> </property> <property> <id>154</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Title 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Title 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Title 3</en> </title> </images> </property> </root>
  20. Hi I have searched around for a solution to this and either fail to grasp how to get it to work or just cannot find the correct solution. I have the following XML file: <?xml version="1.0" encoding="UTF-8"?> <root> <product> <id>153</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> <product> <id>154</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> </root> $xml = 'example.xml'; // URL for feed. try{ $feed = new SimpleXMLElement($xml, null, true); }catch(Exception $e){ echo $e->getMessage(); exit; } $sql = 'INSERT INTO images (`id`, `url`) VALUES '; foreach($feed->property as $property){ $sql .= sprintf( "\n('%d', '%s'),", $property->id, mysql_real_escape_string($property->images->image->url) ); } $sql = rtrim($sql, ',') . ';'; What I need to do is loop through each of the image url nodes and insert them into my DB with the relevant id. Can somebody point me in the right direction with this please its driving me nuts! Regards GT
  21. Hi This article may be of some help http://nadeausoftware.com/articles/2008/04/php_tip_how_extract_keywords_web_page GT
  22. Hi I have been trying to grab some data from an XML feed parse it and then insert it into a database. I will only need to do this on one occasion so no update or deletes. Sample of xml structure: <property> <id>34935</id> <date>2009-11-03 06:52:45</date> <ref>SVS0108</ref> <price>450000</price> <currency>EUR</currency> <price_freq>sale</price_freq> </property> Using xml2array class to parse the feed: <?php /** * xml2array Class * Uses PHP 5 DOM Functions * * This class converts XML data to array representation. * */ class Xml2Array { /** * XML Dom instance * * @var XML DOM Instance */ private $xml_dom; /** * Array representing xml * * @var array */ private $xml_array; /** * XML data * * @var String */ private $xml; public function __construct($xml = '') { $this->xml = $xml; } public function setXml($xml) { if(!empty($xml)) { $this->xml = $xml; } } /** * Change xml data-to-array * * @return Array */ public function get_array() { if($this->get_dom() === false) { return false; } $this->xml_array = array(); $root_element = $this->xml_dom->firstChild; $this->xml_array[$root_element->tagName] = $this->node_2_array($root_element); return $this->xml_array; } private function node_2_array($dom_element) { if($dom_element->nodeType != XML_ELEMENT_NODE) { return false; } $children = $dom_element->childNodes; foreach($children as $child) { if($child->nodeType != XML_ELEMENT_NODE) { continue; } $prefix = ($child->prefix) ? $child->prefix.':' : ''; if(!is_array($result[$prefix.$child->nodeName])) { $subnode = false; foreach($children as $test_node) { if($child->nodeName == $test_node->nodeName && !$child->isSameNode($test_node)) { $subnode = true; break; } } } else { $subnode = true; } if ($subnode) { $result[$prefix.$child->nodeName][] = $this->node_2_array($child); } else { $result[$prefix.$child->nodeName] = $this->node_2_array($child); } } if (!is_array($result)) { $result['#text'] = html_entity_decode(htmlentities($dom_element->nodeValue, ENT_COMPAT, 'UTF-8'), ENT_COMPAT,'ISO-8859-15'); } if ($dom_element->hasAttributes()) { foreach ($dom_element->attributes as $attrib) { $prefix = ($attrib->prefix) ? $attrib->prefix.':' : ''; $result["@".$prefix.$attrib->nodeName] = $attrib->nodeValue; } } return $result; } /** * Generated XML Dom * */ private function get_dom() { if(empty($this->xml)) { echo 'No XML found. Please set XML data using setXML($xml)'; return false; } $this->xml_dom = @DOMDocument::loadXML($this->xml); if($this->xml_dom) { return $this->xml_dom; } echo 'Invalid XML data'; exit; } } ?> My results page: <?php require_once('classes/xml2array.php'); require_once('conn.php'); function curlURL($url) { $ch= curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); $output = curl_exec($ch); return $output; } $curlResults = curlURL("http://localhost/alphashare_dump/property.xml"); $xml = $curlResults; $converter = new Xml2Array(); $converter->setXml($xml); $xml_array = $converter->get_array(); $array = ($xml_array['root']['property']); echo "<pre>"; print_r($array); echo "</pre>"; ////////////// INSERT DATA INTO DB //////////////////////////////////////////////////// ?> My array structure looks like this: Array ( [0] => Array ( [id] => Array ( [#text] => 34935 ) [date] => Array ( [#text] => 2009-11-03 06:52:45 ) [ref] => Array ( [#text] => SVS0108 ) [price] => Array ( [#text] => 450000 ) [currency] => Array ( [#text] => EUR ) [price_freq] => Array ( [#text] => sale ) [part_ownership] => Array ( [#text] => 0 ) Can somebody help with actually getting this into some format that will enable me to insert this into my database please GT
  23. Hi Nobody is thick around here Magpie looks difficult at first glance but if you run through the supplied example it is fairly simple to execute. The first time I used it I created a static XML file with some simple content then added to this as I got to understand the workings more. Have a go at it you will always get advise here if you get stuck. GT
×
×
  • 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.