Almost There - Really Need Your Help Please

3 replies
Hi,

I took a year out to go night school but I have spent nearly 3 years trying to build a hand coded site. I am really pleased with and I have really enjoyed it. However I am stuck on the final stage.

I need to allocate different peices of furniture to a room for my navigation however I cant get the code to work. At the end of the code is a small script which reads one column ($long_name) and is supposed identify key words and insert another keyword into $room.

For example if "coffee table" is in $long_name it inserts "living room" into $room.

However I cant get this piece of code to work. Any help would be greatfully appreciated. To be honest the stress is killing me.

PHP Code:
{      = ("datafeed_98057.xml"); //file inside archive     if(!)         die("Error: can't get stream to zipped file");      = "";      ob_start();     while (!feof())           .= fread(, 2048);      = ob_get_contents();     ob_end_clean();     if(stripos(, "CRC error") != FALSE)         die('CRC32 mismatch');     fclose();     ();      = strocc(, '<prod', '</prod>');          echo '<pre>';     for(=0; <sizeof(); ++)     {           = ;         echo strpp(, '<pId>', '</pId>') ."<br />";          = '';         if(strpos(, '<desc>')!==FALSE)         {              = safe_string_escape(strpp(, '<desc>', '</desc>'));         }          = 0;         if(floatval(strpp(, '<rrp>', '</rrp>'))!=0)              = 100 - (floatval(strpp(, '<buynow>', '</buynow>')) / floatval(strpp(, '<rrp>', '</rrp>')) * 100);         mysql_query("insert into productdbase SET                        image_link = '" .safe_string_escape(strpp(, '<awImage>', '</awImage>')) ."',                       link = '" .safe_string_escape(strpp(, '<awTrack>', '</awTrack>')) ."',                       name = '" .safe_string_escape(strpp(, '<name>', '</name>')) ."',                       linkname = '" .str_replace("---", "-", str_replace(" ", "-", safe_string_escape(strpp(, '<name>', '</name>')))) ."',                       fulldescription = '',                       price = '" .safe_string_escape(strpp(, '<rrp>', '</rrp>')) ."',                       discount = '',                       merchant = '" .safe_string_escape(strpp(, 'name="', '"')) ."',                       promotional_text = '',                       id = '" .strpp(, '<pId>', '</pId>') ."'");                                            mysql_query("insert into furniture_groups SET                        long_name = '" .safe_string_escape(strpp(, '<mCat>', '</mCat>')) ."',                       short_name = '" .safe_string_escape(strpp(, '<awCat>', '</awCat>')) ."',                       id = '" .strpp(, '<pId>', '</pId>') ."'");                                    //echo mysql_error();     } } else     echo "zip not found"; unlink();     function strocc(, , ) {     =0;     =array();     while(strpos(, , ) && strpos(, , strpos(, , )))     {         array_push(, strpp(, , , ));          = strpos(, , strpos(, , ));     }     return (); }   function strpp(, , , =0) {     return substr(, (strpos(, , )+strlen()), strpos(, , strpos(, , )+strlen())-(strpos(, , )+strlen())); }  function mysqlinit(, , , ='localhost') {      = mysql_connect(, , );     if (!)     {         echo('Cant connect to MySQL : ' .mysql_error());         return 0;     }      = mysql_select_db(, );     if (!)     {         echo('Cant use database ' . .': ' .mysql_error());         return 0;     }     return 1; }   function safe_string_escape() {     =strlen();     =0;     ='';     for(=0;<;++) {         switch(=) {             case "'":                 if( % 2 == 0) .="\";                 =0;                 .=;                 break;             case '"':                 if( % 2 == 0) .="\";                 =0;                 .=;                 break;             case '\':                 ++;                 .=;                  break;             default:                 =0;                 .=;         }     }     return ; }    ('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');  ?> 
  • Profile picture of the author justlukeyou
    OMG how do I display code on this site? Im using the code and PPH tags!


    Code:
    { 	 = ("datafeed_98057.xml"); //file inside archive 	if(!) 		die("Error: can't get stream to zipped file"); 	 = "";  	ob_start(); 	while (!feof())  		 .= fread(, 2048); 	 = ob_get_contents(); 	ob_end_clean(); 	if(stripos(, "CRC error") != FALSE) 		die('CRC32 mismatch'); 	fclose(); 	(); 	 = strocc(, '<prod', '</prod>'); 	 	echo '<pre>'; 	for(=0; <sizeof(); ++) 	{  		 = ; 		echo strpp(, '<pId>', '</pId>') ."<br />"; 		 = ''; 		if(strpos(, '<desc>')!==FALSE) 		{ 			 = safe_string_escape(strpp(, '<desc>', '</desc>')); 		} 		 = 0; 		if(floatval(strpp(, '<rrp>', '</rrp>'))!=0) 			 = 100 - (floatval(strpp(, '<buynow>', '</buynow>')) / floatval(strpp(, '<rrp>', '</rrp>')) * 100); 		mysql_query("insert into productdbase SET   					 image_link = '" .safe_string_escape(strpp(, '<awImage>', '</awImage>')) ."',  				     link = '" .safe_string_escape(strpp(, '<awTrack>', '</awTrack>')) ."',  					 name = '" .safe_string_escape(strpp(, '<name>', '</name>')) ."',  					 linkname = '" .str_replace("---", "-", str_replace(" ", "-", safe_string_escape(strpp(, '<name>', '</name>')))) ."',  					 fulldescription = '',  				     price = '" .safe_string_escape(strpp(, '<rrp>', '</rrp>')) ."',  					 discount = '',  					 merchant = '" .safe_string_escape(strpp(, 'name="', '"')) ."',  					 promotional_text = '',  				     id = '" .strpp(, '<pId>', '</pId>') ."'"); 					  			 		mysql_query("insert into furniture_groups SET   					 long_name = '" .safe_string_escape(strpp(, '<mCat>', '</mCat>')) ."',  					 short_name = '" .safe_string_escape(strpp(, '<awCat>', '</awCat>')) ."',  				     id = '" .strpp(, '<pId>', '</pId>') ."'");	  					  		//echo mysql_error(); 	} } else 	echo "zip not found"; unlink();     function strocc(, , ) { 	=0; 	=array(); 	while(strpos(, , ) && strpos(, , strpos(, , ))) 	{ 		array_push(, strpp(, , , )); 		 = strpos(, , strpos(, , )); 	} 	return (); }   function strpp(, , , =0) { 	return substr(, (strpos(, , )+strlen()), strpos(, , strpos(, , )+strlen())-(strpos(, , )+strlen())); }  function mysqlinit(, , , ='localhost') { 	 = mysql_connect(, , ); 	if (!) 	{ 		echo('Cant connect to MySQL : ' .mysql_error()); 		return 0; 	} 	 = mysql_select_db(, ); 	if (!) 	{ 		echo('Cant use database ' . .': ' .mysql_error()); 		return 0; 	} 	return 1; }   function safe_string_escape() { 	=strlen(); 	=0; 	=''; 	for(=0;<;++) { 		switch(=) { 			case "'": 				if( % 2 == 0) .="\"; 				=0; 				.=; 				break; 			case '"': 				if( % 2 == 0) .="\"; 				=0; 				.=; 				break; 			case '\': 				++; 				.=;  				break; 			default: 				=0; 				.=; 		} 	} 	return ; }    ('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');  ?>
    {{ DiscussionBoard.errors[8390500].message }}
    • Profile picture of the author Brandon Tanner
      The 'PHP' and 'Code' tags strip a lot of stuff out (kind of defeats their purpose, lol). So if it's more than a handful of lines of code, just use Pastebin (or something similar), and post a link to it.
      Signature

      {{ DiscussionBoard.errors[8390598].message }}
  • Profile picture of the author David Beroff
    It does appear that a lot was stripped from your original code, but from what I can see, it would appear that you have have hardcoded all of your allocation logic into your web page. Perhaps it would be a lot less stressful for you if you were to add a new allocation table for all of these rules, allowing for a simple loop to categorize things as desired, plus giving you better opportunity to change your rules more easily in the future.
    Signature
    Put MY voice on YOUR video: AwesomeAmericanAudio.com
    {{ DiscussionBoard.errors[8391721].message }}

Trending Topics