Jump to content

justlukeyou

Members
  • Posts

    957
  • Joined

  • Last visited

Posts posted by justlukeyou

  1. Thanks Kevin,

     

    I used another site but the guy did try to sting me. Its a like a garage changing 3 tyres for $300 but then offering $150 to do the fourth tyre.

     

    Luckily though I have been able to make some of the additions. The final thing I need to is to read the $long_name and select keywords and insert another keywork into $room

     

    For example "coffee table" from $long_name is inserted into $room as "living room".

     

    $dbh->query('UPDATE `furniture_groups` SET `room` = CASE
    				 WHEN `long_name` LIKE \'%kitchen%\' THEN \'Kitchen\'
    				 WHEN `long_name` LIKE \'%coffee%\'  THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%living%\'  THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%sofa%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%otto%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%tv%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%cd%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%lounger%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%mirror%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%sideboard%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%lounge%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%nest of table%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%entertainment%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%bed%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%mattr%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%stool%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%wardrobe%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%chest%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%blanket box%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%headboard%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%futon%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%hall%\' 	 THEN \'Hall\'
    				 WHEN `long_name` LIKE \'%bath%\' 	 THEN \'Bathroom\'
    				 WHEN `long_name` LIKE \'%dressing%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%office%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%bookcase%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%filing%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%computer desk%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%extending%\' 	 THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%extendable%\'  THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%dining%\' 	 THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%wine rack%\' 	 THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%cushion%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%rug%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%vase%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%lamp%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%clock%\' 	 THEN \'Home-Furnishings\'
    				 ELSE `room`
    				 END');
    
    ?>
    
    
    
        Mark Solved
        Quote
        MultiQuote
        Report
    
  2. Thanks requinix,

     

    Getting there with it. I can insert the two columns into the second table. Now I need to filter which room each pirticular peice of furniture goes into. I have added a filter at the end but it is from another cron job which did work.

     

    I think I need to change the $dbh but not sure what to.

     

     

    {
    	$fp = $zip->getStream("datafeed_98057.xml"); //file inside archive
    	if(!$fp)
    		die("Error: can't get stream to zipped file");
    	$buf = ""; 
    	ob_start();
    	while (!feof($fp)) 
    		$buf .= fread($fp, 2048);
    	$s = ob_get_contents();
    	ob_end_clean();
    	if(stripos($s, "CRC error") != FALSE)
    		die('CRC32 mismatch');
    	fclose($fp);
    	$zip->close();
    	$ax = strocc($buf, '<prod', '</prod>');
    	
    	echo '<pre>';
    	for($i=0; $i<sizeof($ax); $i++)
    	{ 
    		$arr = $ax[$i];
    		echo strpp($arr, '<pId>', '</pId>') ."<br />";
    		$desc = '';
    		if(strpos($ax[$i], '<desc>')!==FALSE)
    		{
    			$desc = safe_string_escape(strpp($ax[$i], '<desc>', '</desc>'));
    		}
    		$discount = 0;
    		if(floatval(strpp($arr, '<rrp>', '</rrp>'))!=0)
    			$discount = 100 - (floatval(strpp($arr, '<buynow>', '</buynow>')) / floatval(strpp($arr, '<rrp>', '</rrp>')) * 100);
    		mysql_query("insert into productdbase SET  
    					 image_link = '" .safe_string_escape(strpp($arr, '<awImage>', '</awImage>')) ."', 
    				     link = '" .safe_string_escape(strpp($arr, '<awTrack>', '</awTrack>')) ."', 
    					 name = '" .safe_string_escape(strpp($arr, '<name>', '</name>')) ."', 
    					 linkname = '" .str_replace("---", "-", str_replace(" ", "-", safe_string_escape(strpp($arr, '<name>', '</name>')))) ."', 
    					 fulldescription = '$desc', 
    				     price = '" .safe_string_escape(strpp($arr, '<rrp>', '</rrp>')) ."', 
    					 discount = '$discount', 
    					 merchant = '" .safe_string_escape(strpp($arr, 'name="', '"')) ."', 
    					 promotional_text = '$desc', 
    				     id = '" .strpp($arr, '<pId>', '</pId>') ."'");
    					 
    			
    		mysql_query("insert into furniture_groups SET  
    					 long_name = '" .safe_string_escape(strpp($arr, '<mCat>', '</mCat>')) ."', 
    					 short_name = '" .safe_string_escape(strpp($arr, '<awCat>', '</awCat>')) ."', 
    				     id = '" .strpp($arr, '<pId>', '</pId>') ."'");	 
    					 
    		//echo mysql_error();
    	}
    }
    else
    	echo "zip not found";
    unlink($file);
    
    
    
    
    function strocc($str, $pos1, $pos2)
    {
    	$pos=0;
    	$occ=array();
    	while(strpos($str, $pos1, $pos) && strpos($str, $pos2, strpos($str, $pos1, $pos)))
    	{
    		array_push($occ, strpp($str, $pos1, $pos2, $pos));
    		$pos = strpos($str, $pos2, strpos($str, $pos1, $pos));
    	}
    	return ($occ);
    } 
    
    function strpp($str, $pos1, $pos2, $startoffset=0)
    {
    	return substr($str, (strpos($str, $pos1, $startoffset)+strlen($pos1)), strpos($str, $pos2, strpos($str, $pos1, $startoffset)+strlen($pos1))-(strpos($str, $pos1, $startoffset)+strlen($pos1)));
    }
    
    function mysqlinit($user, $pass, $db, $host='localhost')
    {
    	$link = mysql_connect($host, $user, $pass);
    	if (!$link)
    	{
    		echo('Cant connect to MySQL : ' .mysql_error());
    		return 0;
    	}
    	$db_selected = mysql_select_db($db, $link);
    	if (!$db_selected)
    	{
    		echo('Cant use database ' .$db .': ' .mysql_error());
    		return 0;
    	}
    	return 1;
    }
    
    
    function safe_string_escape($str)
    {
    	$len=strlen($str);
    	$escapeCount=0;
    	$targetString='';
    	for($offset=0;$offset<$len;$offset++) {
    		switch($c=$str{$offset}) {
    			case "'":
    				if($escapeCount % 2 == 0) $targetString.="\\";
    				$escapeCount=0;
    				$targetString.=$c;
    				break;
    			case '"':
    				if($escapeCount % 2 == 0) $targetString.="\\";
    				$escapeCount=0;
    				$targetString.=$c;
    				break;
    			case '\\':
    				$escapeCount++;
    				$targetString.=$c; 
    				break;
    			default:
    				$escapeCount=0;
    				$targetString.=$c;
    		}
    	}
    	return $targetString;
    }
    
    
    
    $dbh->query('UPDATE `furniture_groups` SET `room` = CASE
    				 WHEN `long_name` LIKE \'%kitchen%\' THEN \'Kitchen\'
    				 WHEN `long_name` LIKE \'%coffee%\'  THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%living%\'  THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%sofa%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%otto%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%tv%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%cd%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%lounger%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%mirror%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%sideboard%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%lounge%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%nest of table%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%entertainment%\' 	 THEN \'Living-room\'
    				 WHEN `long_name` LIKE \'%bed%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%mattr%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%stool%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%wardrobe%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%chest%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%blanket box%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%headboard%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%futon%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%hall%\' 	 THEN \'Hall\'
    				 WHEN `long_name` LIKE \'%bath%\' 	 THEN \'Bathroom\'
    				 WHEN `long_name` LIKE \'%dressing%\' 	 THEN \'Bedroom\'
    				 WHEN `long_name` LIKE \'%office%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%bookcase%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%filing%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%computer desk%\' 	 THEN \'Office\'
    				 WHEN `long_name` LIKE \'%extending%\' 	 THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%extendable%\'  THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%dining%\' 	 THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%wine rack%\' 	 THEN \'Dining-Room\'
    				 WHEN `long_name` LIKE \'%cushion%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%rug%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%vase%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%lamp%\' 	 THEN \'Home-Furnishings\'
    				 WHEN `long_name` LIKE \'%clock%\' 	 THEN \'Home-Furnishings\'
    				 ELSE `room`
    				 END');
    
    ?>
    
    
    
    
  3. Hi,

     

    But the additional work is far less than the original work.

     

    I've had a go at it. I can get the second insert into furniture_groups to only insert one line. But the first insert into productdbase inserts everything I need. Cant see why though.

     

    		if(floatval(strpp($arr, '<rrp>', '</rrp>'))!=0)
    			$discount = 100 - (floatval(strpp($arr, '<buynow>', '</buynow>')) / floatval(strpp($arr, '<rrp>', '</rrp>')) * 100);
    		mysql_query("insert into productdbase SET  
    					 image_link = '" .safe_string_escape(strpp($arr, '<awImage>', '</awImage>')) ."', 
    				     link = '" .safe_string_escape(strpp($arr, '<awTrack>', '</awTrack>')) ."', 
    					 name = '" .safe_string_escape(strpp($arr, '<name>', '</name>')) ."', 
    					 linkname = '" .str_replace("---", "-", str_replace(" ", "-", safe_string_escape(strpp($arr, '<name>', '</name>')))) ."', 
    					 fulldescription = '$desc', 
    				     price = '" .safe_string_escape(strpp($arr, '<rrp>', '</rrp>')) ."', 
    					 discount = '$discount', 
    					 merchant = '" .safe_string_escape(strpp($arr, 'name="', '"')) ."', 
    					 promotional_text = '$desc', 
    				     id = '" .strpp($arr, '<pId>', '</pId>') ."'");
    					 
    			
    		mysql_query("insert into furniture_groups SET  
    					 long_name = '" .safe_string_escape(1) ."',  
    					 short_name = '" .safe_string_escape(strpp($arr, '<mCat>', '</mCat>')) ."', 
    				     id = '" .strpp($arr, '<pId>', '</pId>') ."'");	 
    					 
    		//echo mysql_error();
    	}
    }
    
  4. Hi,

     

    I paid someone $30 to create the following Cron Job on Freelancer. However when I requested further work to be added he put up the prices to $50 as if he was trying to blackmail me.

     

    All I am trying to do is to insert some of the code into a second table so I can sort it. Is it possible to do it with the following easily enough? Would I just use an else code on the first set of insert?

     

     

     

    $fp = $zip->getStream("datafeed_98057.xml"); //file inside archive
    	if(!$fp)
    		die("Error: can't get stream to zipped file");
    	$buf = ""; 
    	ob_start();
    	while (!feof($fp)) 
    		$buf .= fread($fp, 2048);
    	$s = ob_get_contents();
    	ob_end_clean();
    	if(stripos($s, "CRC error") != FALSE)
    		die('CRC32 mismatch');
    	fclose($fp);
    	$zip->close();
    	$ax = strocc($buf, '<prod', '</prod>');
    	
    	echo '<pre>';
    	for($i=0; $i<sizeof($ax); $i++)
    	{ 
    		$arr = $ax[$i];
    		echo strpp($arr, '<pId>', '</pId>') ."<br />";
    		$desc = '';
    		if(strpos($ax[$i], '<desc>')!==FALSE)
    		{
    			$desc = safe_string_escape(strpp($ax[$i], '<desc>', '</desc>'));
    		}
    		$discount = 0;
    		if(floatval(strpp($arr, '<rrp>', '</rrp>'))!=0)
    			$discount = 100 - (floatval(strpp($arr, '<buynow>', '</buynow>')) / floatval(strpp($arr, '<rrp>', '</rrp>')) * 100);
    		mysql_query("insert into productdbase SET  category_name = '" .safe_string_escape(strpp($arr, '<awCat>', '</awCat>')) ."',  
    					 merchant_category = '" .safe_string_escape(strpp($arr, '<mCat>', '</mCat>')) ."', 
    					 image_link = '" .safe_string_escape(strpp($arr, '<awImage>', '</awImage>')) ."', 
    				     link = '" .safe_string_escape(strpp($arr, '<awTrack>', '</awTrack>')) ."', 
    					 name = '" .safe_string_escape(strpp($arr, '<name>', '</name>')) ."', 
    					 linkname = '" .str_replace("---", "-", str_replace(" ", "-", safe_string_escape(strpp($arr, '<name>', '</name>')))) ."', 
    					 fulldescription = '$desc', 
    				     price = '" .safe_string_escape(strpp($arr, '<rrp>', '</rrp>')) ."', 
    					 discount = '$discount', 
    					 merchant = '" .safe_string_escape(strpp($arr, 'name="', '"')) ."', 
    					 promotional_text = '$desc', 
    				     id = '" .strpp($arr, '<pId>', '</pId>') ."'");
    		//echo mysql_error();
    	}
    }
    else
    	echo "zip not found";
    unlink($file);
    
    
    function strocc($str, $pos1, $pos2)
    {
    	$pos=0;
    	$occ=array();
    	while(strpos($str, $pos1, $pos) && strpos($str, $pos2, strpos($str, $pos1, $pos)))
    	{
    		array_push($occ, strpp($str, $pos1, $pos2, $pos));
    		$pos = strpos($str, $pos2, strpos($str, $pos1, $pos));
    	}
    	return ($occ);
    } 
    
    function strpp($str, $pos1, $pos2, $startoffset=0)
    {
    	return substr($str, (strpos($str, $pos1, $startoffset)+strlen($pos1)), strpos($str, $pos2, strpos($str, $pos1, $startoffset)+strlen($pos1))-(strpos($str, $pos1, $startoffset)+strlen($pos1)));
    }
    
    function mysqlinit($user, $pass, $db, $host='localhost')
    {
    	$link = mysql_connect($host, $user, $pass);
    	if (!$link)
    	{
    		echo('Cant connect to MySQL : ' .mysql_error());
    		return 0;
    	}
    	$db_selected = mysql_select_db($db, $link);
    	if (!$db_selected)
    	{
    		echo('Cant use database ' .$db .': ' .mysql_error());
    		return 0;
    	}
    	return 1;
    }
    
    
    function safe_string_escape($str)
    {
    	$len=strlen($str);
    	$escapeCount=0;
    	$targetString='';
    	for($offset=0;$offset<$len;$offset++) {
    		switch($c=$str{$offset}) {
    			case "'":
    				if($escapeCount % 2 == 0) $targetString.="\\";
    				$escapeCount=0;
    				$targetString.=$c;
    				break;
    			case '"':
    				if($escapeCount % 2 == 0) $targetString.="\\";
    				$escapeCount=0;
    				$targetString.=$c;
    				break;
    			case '\\':
    				$escapeCount++;
    				$targetString.=$c; 
    				break;
    			default:
    				$escapeCount=0;
    				$targetString.=$c;
    		}
    	}
    	return $targetString;
    }
    ?>
    
  5. Thanks,

     

    I have tried that but it has had no impact. Is it possible only affect how the products link works as this is the only page I want to have a slug in the title. The other links within site are fine with just one variable in.

     

    RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    
  6. Hi,

     

    I have fixed one problem only to make another one.

     

    I have added a piece of code to my htaccess file which allows me to add the product title to the link for SEO purposes=

     

    .com/123456/large-red-widget

     

    However it now affects all the other links which have a query in. Can anyone advise how I can just isolate products/product to have a second variable after the one which operates the query?

     

     

      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    
    RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
      RewriteRule ^articles/article/([0-9]+)/(.*)$ articles/article.php?ID=$1 [QSA,L]
        RewriteRule ^articles/articlesfiltered/([A-Za-z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
      RewriteRule ^plusstyle/plusstyle/([0-9]+)/(.*)$ plusstyle/plusstyle.php?ID=$1 [QSA,L]
       RewriteRule ^plusstyle/plusstylesfiltered/([A-Za-z]+)/(.*)$ plusstyle/plusstylesfiltered.php?articlecategory=$1 [QSA,L]
    
  7. Sorted it!

     

    Does anyone have any views on this code? Are there any improvements I can make?

     

           $prod = new SimpleXMLElement($domString);
                        $id = $prod->attributes();
                        $id = $id['id'];
                        $link = $prod->uri->awTrack;
    					$producttitle = mysql_real_escape_string($prod->text->name);
                        $fulldescription = mysql_real_escape_string($prod->text->desc);
    		    $category_name = $prod->uri->category_name;
    			$product_name = mysql_real_escape_string($prod->text->name);
    			$link_name = strtolower(str_replace(array(' ', '_'), '-', preg_replace('#[^A-Za-z0-9 \-_]#', '', $product_name)));
                        $merchant_category = $prod->uri->merchant_category;
    		    $image = $prod->uri->awImage;
    			$productlink = (string)$product->uri->awTrack;
                        $retailprice = $prod->price->rrp;
                        $sellprice = $prod->price->buynow;
                        if($id) {
                            if($sellprice > 0 && $retailprice > 0) {
                                $discount = 100 - ($sellprice / $retailprice * 100);
                            } else {
                                $discount = 0;
                            }
                            echo "New product: #" . $id . " - " . $category_name . " . $merchant_category ." . $producttitle . " - Discount: " . $discount . "%" . 
    
    (($discount > 90.01 || $discount < 0) ? " (Not inserted)" : " (Inserted)") . "<br />" 
    . $link_name . "<br />"
    . $fulldescription . "<br /><br />";
                            if($discount > 0 && $discount < 90.01) {
                                $query = mysql_query("SELECT * FROM productdbase WHERE id = '".$id."'");
                                if(mysql_num_rows($query) > 0) {
                                    $query = mysql_query("UPDATE productdbase SET  category_name = '".$category_name."',  merchant_category = '".$productlink."', 
    
    image_link = '".$image."', link = '".$link."', name = '".$producttitle."', fulldescription = '".$fulldescription."',  sell_price = '".$sellprice."', discount = 
    
    '".round($discount)."', linkname = '".$link_name."',  merchant = '".$merchant."' WHERE id = '".$id."'");
                                } else {
                                    $query = mysql_query("INSERT INTO productdbase (id, category_name, merchant_category, linkname, image_link, link, name, 
    
    fulldescription, price, discount, merchant) VALUES ('".$id."', '".$category_name."', '".$merchant_category."', '".$link_name."', '".$image."', '".$link."', '".
    
    $producttitle."', '".$fulldescription."', '".$sellprice."', '".round($discount)."', '".$merchant."')");
                                }
                                if($query) {
                                    echo $id . " has been inserted.<br />";
                                } else {
                                    echo $id . " could not be inserted because: " . mysql_error() . ".<br />";
                                }
                            }
                        } else {
                            echo "Could not retrieve the product information.<br />";
                        }
                    }
                    break;
    
  8. Hi,

     

    I have made alot of progress. I am now declaring the values but I am still struggling to understand how each areas correlates.

     

    Can anyone advise please?

     

    // Unzip the files.
    //require_once("dunzip2.class.php");
    //$url = "http://datafeed.api.productserve.com/datafeed/download/apikey/ca79e5c05777a469065377372c824696/cid/424,451,448,453,449,452,450/mid/495,1829/columns/merchant_id,merchant_name,aw_product_id,merchant_product_id,product_name,description,category_id,category_name,merchant_category,aw_deep_link,aw_image_url,search_price,delivery_cost,merchant_deep_link,merchant_image_url,rrp_price/format/xml/compression/zip/";
    $url = "http://datafeed.api.productserve.com/datafeed/download/apikey/ca79e5c05777a469065377372c824696/cid/424,451,448,453,449,452,450/mid/495,1829/columns/merchant_id,merchant_name,aw_product_id,merchant_product_id,product_name,description,category_id,category_name,merchant_category,aw_deep_link,aw_image_url,search_price,delivery_cost,merchant_deep_link,merchant_image_url,rrp_price/format/xml/compression/zip/";
    $contents = file_get_contents($url);
    file_put_contents("datafeed_98057.xml.zip", $contents);
    //$zip = new dUnzip2("datafeed_98057.xml.zip");
    //$zip->getList();
    //$zip->unzipAll();
    system("unzip -qq datafeed_98057.xml.zip");
    
    // Fetch the feed and fix the broken end-tags.
    $filename = "datafeed_98057.xml";
    $feed = file_get_contents($filename);
    
    // Start up the XML Reader.
    $xmlReader = new XMLReader();
    $xmlReader->open($filename);
    
    // Loop through the file, and do all the extraction.
    while($xmlReader->read()) {
        if($xmlReader->nodeType == XmlReader::END_ELEMENT) {
        } else {
            switch($xmlReader->name) {
                case "merchant":
                    echo "New merchant: " . $xmlReader->getAttribute("name") . "<br />";
                    $merchant = mysql_real_escape_string($xmlReader->getAttribute("name"));
                    break;
                case "prod":
                    $dom = new DOMDocument();
                    $domNode = $xmlReader->expand();
                    $element = $dom->appendChild($domNode);
                    $domString = utf8_encode($dom->saveXML($element));
                    if(trim($domString) != "") {
                        $prod = new SimpleXMLElement($domString);
                        $id = $prod->attributes();
                        $id = $id['id'];
                        $link = $prod->uri->awTrack;
    					$producttitle = mysql_real_escape_string($prod->text->name);
                        $fulldescription = mysql_real_escape_string($prod->text->desc);
    		    $category_name = $prod->uri->category_name;
                        $merchant_category = $prod->uri->merchant_category;
    		    $image = $prod->uri->awImage;
    			$productlink = (string)$product->uri->awTrack;
                        $retailprice = $prod->price->rrp;
                        $sellprice = $prod->price->buynow;
                        if($id) {
                            if($sellprice > 0 && $retailprice > 0) {
                                $discount = 100 - ($sellprice / $retailprice * 100);
                            } else {
                                $discount = 0;
                            }
                            echo "New product: #" . $id . " - " . $category_name . " . $merchant_category ." . $producttitle . " - Discount: " . $discount . "%" . (($discount > 90.01 || $discount < 0) ? " (Not inserted)" : " (Inserted)") . "<br />" . $fulldescription . "<br /><br />";
                            if($discount > 0 && $discount < 90.01) {
                                $query = mysql_query("SELECT * FROM productdbase WHERE id = '".$id."'");
                                if(mysql_num_rows($query) > 0) {
                                    $query = mysql_query("UPDATE productdbase SET  category_name = '".$category_name."',  merchant_category = '".$productlink."', image_link = '".$image."', link = '".$link."', name = '".$producttitle."', fulldescription = '".$fulldescription."',  sell_price = '".$sellprice."', discount = '".round($discount)."', merchant = '".$merchant."' WHERE id = '".$id."'");
                                } else {
                                    $query = mysql_query("INSERT INTO productdbase (id, category_name, merchant_category, image_link, link, name, fulldescription, price, discount, merchant) VALUES ('".$id."', '".$category_name."', '".$merchant_category."', '".$image."', '".$link."', '".$producttitle."', '".$fulldescription."', '".$sellprice."', '".round($discount)."', '".$merchant."')");
                                }
                                if($query) {
                                    echo $id . " has been inserted.<br />";
                                } else {
                                    echo $id . " could not be inserted because: " . mysql_error() . ".<br />";
                                }
                            }
                        } else {
                            echo "Could not retrieve the product information.<br />";
                        }
                    }
                    break;
            }
        }
    }
    
    // Close the XML Reader and free memory.
    $xmlReader->close();
    unset($feed);
    unlink("datafeed_98057.xml");
    unlink("datafeed_98057.xml.zip");
    
    ?>
    
  9.  

    // if you need all parts to make more decisions
    // $parts = explode('/', $_GET['url']);
    // $product_id = last($parts);
    // for just the last
    $product_id = basename($_GET['url']);
    // SELECT blah FROM blah WHERE product_id = $product_id
    This will have to be expanded upon because you need to know it's products and not faq or whatever else, but all the info is in the $_GET['url'] for you to parse and use etc.. so you can use the explode() method.

     

    Many thanks,

     

    Im not sure what this part means though. What part of the code allows two variables to be in a link but only the second variable is the query.

  10. Aw hell, now the links to the pages don't work. Well some work but others dont. Unbelievable.

     

    This links works.

     

    .com/articles/articles

     

    But this doesn't

     

    .com/products/products

     

    I've tried reverting back to my old files but they are still not working.

     

     

     

     

     

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
    
    # Disable directory listing from this point
    Options -Indexes
    
    # Prevent viewing of htaccess file
    <Files ~ "^\.ht">
    order allow,deny
    deny from all
    satisfy all
    </Files>
    
    # Error Pages
    ErrorDocument 404 /404-error.php
    
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^ index.php [L]
     RewriteRule ^products/product/([a-zA-Z0-9]+)/(.*)$ /products/product.php?product_id=$1
    </IfModule>
    
  11.  

     

    1. This currently works... /products/product/713972992

     

    2. Not sure what this means. But product_id is the only unique reference I have.

     

    3. Looking for something like this... /products/product/713972992/red-widget or /products/product/red-widget/713972992

     

    4. Not sure what this means.

  12. This code seems to work the same as having to write out each individual page so it makes the code a lot simpler.

     

     

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^ index.php [L]
    </IfModule>
    
    What I am stuck on is using a variable as a slug within the link.

     

    This is a classic example of what I am looking to achieve.

     

    johnlewis.com/john-lewis-lasko-chest-of-drawers-oak/p230674902

  13. Hi,

     

    I having Googling and as far as I can tell I need add a 'dummy slug'. However I cant see how I add a dummy slug onto the query.

     

    Do I need something like this?

     

    /products/product/<?php echo $row['product_id']; ?>/<?php echo $row['linkname']; ?>/

  14. Hi,

     

    I just found this really neat peice of code which appears to tidy up the page much better and doesn't require me to rewrite each and every page.

     

    However I am still unsure how to query with one variable but display another variable in the link.

     

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^ index.php [L]
    </IfModule>
    
  15. Hi,

     

    I have added a link name to database called $linkname. For example "large-red-widget". However my link is querying the database using a unique product ID but I want to display the $linkname within link.

     

    What I dont understand is the relationship between the htaccess file and the way the link is displayed. How I do I display link with linkname but query the databsae using the product_id ?

     

    This works...

     

    /products/product/<?php echo $row['product_id']; ?>" >

     

    RewriteRule ^products/product/([a-zA-Z0-9]+)$ /products/product.php?product_id=$1

    [code]

     

    This doesn't...

     

    /products/product/<?php echo $row['product_id']; ?>" >

     

    [code]

    RewriteRule ^products/product/([a-zA-Z0-9]+)$ /products/product.php?linkname=$1

    [code]

  16. Hi,

     

    I need to declare the values but whenever I try it creates a syntaz error. Is there any way to fix it it please?

     

    (`product_id`, `link`, `name`, `linkname`, `fulldescription`, `image_link`, `rrp`, `sell_price`,`discount`, `merchant`, `furniture_group`)
    						  VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    						   ON DUPLICATE KEY UPDATE `link` = ?, `fulldescription` = ?, `rrp` = ?, `sell_price` = ?, `discount` = ?, `furniture_group` = ?');
    

     

    VALUES ('".$id."', '".$category_name."', '".$merchant_category."', '".$image."', '".$link."', '".$description."', '".$fulldescription."', '".$sellprice."', '".round($discount)."', '".$merchant."')");
    
  17. Hi,

     

    I have spent another 4 hours on this non-stop but still cant get anywhere.

     

    Can anyone advise how this part works please. Whenever I try to add to it, it wont insert.

     

    I have 12 columns and 12 questions marks but I dont understand how to add another column.

     

     

    	$sth = $dbh->prepare('INSERT INTO `productdbase`
    						(`product_id`, `link`, `name`, `linkname`, `fulldescription`, `image_link`, `rrp`, `sell_price`, `discount`, `merchant`, `furniture_group`)
    						  VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    						   ON DUPLICATE KEY UPDATE `link` = ?, `fulldescription` = ?, `rrp` = ?, `sell_price` = ?, `discount` = ?, `furniture_group` = ?');
    						  
    	$sth_fg = $dbh->prepare('INSERT INTO `furniture_groups`
    						   (`long_name`, short_name)
    							 VALUES(?, ?)');
    
  18. Thanks once again.

     

    I am almost there with it. About half the data I need inserting.

     

    Is there a process I can use to see why some data is inserting and other data isn't?

     

    I'm confused as to why the discount calculation works but the values that enter into the calculation don't enter into the table.

  19. Thanks, programming isn't the hobby I want lol its the website that comes from it!!

     

     

    I did have a bash at it and I can now insert some of columns I want to insert which is a great step. Very pleased with that.

     

    However, I still cant actually understand how the code works.

     

    For example, the percentage of the discount inserts so it must be reading the RRP and the sell price. However the RRP and sell price are not entering into the table.

  20. Hi,

     

    Can anyone advise how I can progress with this please? I have tried advertising the job on PeoplePerHourbut I get very basic questions through like "what code is it written in".

     

    I cant seem to find someone to pay to fix it!

     

    How difficult are Cron jobs to set up and use?

  21. Hi,

     

    I have a cron job file. When I run it returns a message that the items have been inserted however nothing is inserting into the database.

     

    Does anyone have any suggestions why it would return this message but not insert into the database and how to fix it please?

     

    
    mysql_connect($host, $username, $password);
    mysql_select_db($database);
    
    // Make it PHP4 compatible.
    if(!function_exists("file_get_contents")) {
        function file_get_contents($filename) {
            $c = curl_init();
            curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($c, CURLOPT_URL, $filename);
            $contents = curl_exec($c);
            curl_close($c);
            if($contents) {
                return $contents;
            } else {
                return curl_error($c);
            }
            return false;
        }
    }
    
    if(!function_exists("file_put_contents")) {
        function file_put_contents($filename, $data) {
            $f = @fopen($filename, "w");
            if(!$f) {
                return false;
            } else {
                $bytes = fwrite($f, $data);
                fclose($f);
                return $bytes;
            }
        }
    }
    
    // Unzip the files.
    //require_once("dunzip2.class.php");
    //$url = "http://datafeed.api.productserve.com/datafeed/download/apikey/ca79e5c05777a469065377372c824696/cid/424,451,448,453,449,452,450/mid/495,1829/columns/merchant_id,merchant_name,aw_product_id,merchant_product_id,product_name,description,category_id,category_name,merchant_category,aw_deep_link,aw_image_url,search_price,delivery_cost,merchant_deep_link,merchant_image_url,rrp_price/format/xml/compression/zip/";
    $url = "http://datafeed.api.productserve.com/datafeed/download/apikey/ca79e5c05777a469065377372c824696/cid/424,451,448,453,449,452,450/mid/495,1829/columns/merchant_id,merchant_name,aw_product_id,merchant_product_id,product_name,description,category_id,category_name,merchant_category,aw_deep_link,aw_image_url,search_price,delivery_cost,merchant_deep_link,merchant_image_url,rrp_price/format/xml/compression/zip/";
    $contents = file_get_contents($url);
    file_put_contents("datafeed_98057.xml.zip", $contents);
    //$zip = new dUnzip2("datafeed_98057.xml.zip");
    //$zip->getList();
    //$zip->unzipAll();
    system("unzip -qq datafeed_98057.xml.zip");
    
    // Fetch the feed and fix the broken end-tags.
    $filename = "datafeed_98057.xml";
    $feed = file_get_contents($filename);
    
    // Start up the XML Reader.
    $xmlReader = new XMLReader();
    $xmlReader->open($filename);
    
    // Loop through the file, and do all the extraction.
    while($xmlReader->read()) {
        if($xmlReader->nodeType == XmlReader::END_ELEMENT) {
        } else {
            switch($xmlReader->name) {
                case "merchant":
                    echo "New merchant: " . $xmlReader->getAttribute("name") . "<br />";
                    $merchant = mysql_real_escape_string($xmlReader->getAttribute("name"));
                    break;
                case "prod":
                    $dom = new DOMDocument();
                    $domNode = $xmlReader->expand();
                    $element = $dom->appendChild($domNode);
                    $domString = utf8_encode($dom->saveXML($element));
                    if(trim($domString) != "") {
                        $prod = new SimpleXMLElement($domString);
                        $id = $prod->attributes();
                        $id = $id['id'];
                        $link = $prod->uri->mLink;
                        $description = mysql_real_escape_string($prod->text->name);
                        $fulldescription = mysql_real_escape_string($prod->text->desc);
    		    $category_name = $prod->uri->category_name;
                        $merchant_category = $prod->uri->merchant_category;
    		    $image = $prod->uri->awImage;
                        $retailprice = $prod->price->rrp;
                        $sellprice = $prod->price->buynow;
                        if($id) {
                            if($sellprice > 0 && $retailprice > 0) {
                                $discount = 100 - ($sellprice / $retailprice * 100);
                            } else {
                                $discount = 0;
                            }
                            echo "New product: #" . $id . " - " . $category_name . " . $merchant_category ." . $description . " - Discount: " . $discount . "%" . (($discount > 90.01 || $discount < 0) ? " (Not inserted)" : " (Inserted)") . "<br />" . $fulldescription . "<br /><br />";
                            if($discount > 0 && $discount < 90.01) {
                                $query = mysql_query("SELECT * FROM productdbasetest WHERE id = '".$id."'");
                                if(mysql_num_rows($query) > 0) {
                                    $query = mysql_query("UPDATE productdbasetest SET  category_name = '".$category_name."',  merchant_category = '".$merchant_category."', awImage = '".$image."', link = '".$link."', description = '".$description."', fulldescription = '".$fulldescription."', price = '".$sellprice."', discount = '".round($discount)."', merchant = '".$merchant."' WHERE id = '".$id."'");
                                } else {
                                    $query = mysql_query("INSERT INTO productdbasetest (id, category_name, merchant_category, awImage, link, description, fulldescription, price, discount, merchant) VALUES ('".$id."', '".$category_name."', '".$merchant_category."', '".$image."', '".$link."', '".$description."', '".$fulldescription."', '".$sellprice."', '".round($discount)."', '".$merchant."')");
                                }
                                if($query) {
                                    echo $id . " has been inserted.<br />";
                                } else {
                                    echo $id . " could not be inserted because: " . mysql_error() . ".<br />";
                                }
                            }
                        } else {
                            echo "Could not retrieve the product information.<br />";
                        }
                    }
                    break;
            }
        }
    }
    
    // Close the XML Reader and free memory.
    $xmlReader->close();
    unset($feed);
    unlink("datafeed_98057.xml");
    unlink("datafeed_98057.xml.zip");
    
    ?>
    
  22. Thanks, I live near a large town but the main book shops doesn't have many computer based books.

     

    When I google PDO it comes up with lots based on connecting to the database. A pro designer from Sweden told me that PDO is all about the connection. Thats why I didn't bother to learn it and focussed on PHP.

×
×
  • 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.