Pieduriens Posted January 30, 2013 Report Share Posted January 30, 2013 Labdien! Ir xml fails, kuru izveido foreach: <root> <item> <name>Nokia 2530</name> <cat> Phones</cat> <price>199</cat> </item> <item> <name>Nokia 2530</name> <cat> Featured</cat> <price>199</cat> </item> </root> Vai ir iespēja pirms echo posma noņemt <item>...</item> daļu, kur cat = featured? Ar cieņu, Kārlis. Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted January 30, 2013 Report Share Posted January 30, 2013 varbūt ar if? Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted January 30, 2013 Author Report Share Posted January 30, 2013 Pa lielam, nākamais solis ir saprotams if.. Varbūt kāds var iedot kādas vadlīnijas? Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 30, 2013 Report Share Posted January 30, 2013 if ($cat != 'featured') { ... } Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted January 30, 2013 Author Report Share Posted January 30, 2013 if ($cat != 'featured') { ... } ok, un kā noselektot visu <item> te iekšā ir "featured" </item> Quote Link to comment Share on other sites More sharing options...
marrtins Posted January 30, 2013 Report Share Posted January 30, 2013 Kur noselektot? Ar ko noselektot? Kur izechot? Troll on! Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted January 30, 2013 Author Report Share Posted January 30, 2013 (edited) Dooh, atvainojos. Viss kods: http://pastebin.com/7KvLDKdP Edited January 30, 2013 by Pieduriens Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 30, 2013 Report Share Posted January 30, 2013 Apmēram šādi, tik pārbaudi, vai nosaukums ir pareizais: //Action if( $catfull != 'featured' ) { echo "<item>"; echo "<name>".$product_type." ".$name."</name>"; echo "<link>".$url."</link>"; echo "<price>".$price."</price>"; echo "<image>".$img."</image>"; echo "<category_full>".$catfull."</category_full>"; echo "<category_link>".$caturl."</category_link>"; echo "<in_stock>".(int)$qty."</in_stock>"; echo "</item>"; } Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted January 30, 2013 Author Report Share Posted January 30, 2013 Axxc ideāli! Pielieku klāt if( $catfull != 'Ieteiktie produkti' && $catfull != 'Specials' ) {...} Paldies ;) Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 30, 2013 Report Share Posted January 30, 2013 Ja tev vajag pārbaudi uz vairākiem, tad ērtāk būs masīvā salikt tos tekstus: if ( !in_array( $catfull, array( 'Ieteiktie produkti', 'Specials' ) ) ) { ... } Šādi būs stipri ērtāk vēlāk pievienot tekstus klāt ( vai noņemt nost ). Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted January 30, 2013 Author Report Share Posted January 30, 2013 Ja tev vajag pārbaudi uz vairākiem, tad ērtāk būs masīvā salikt tos tekstus: if ( !in_array( $catfull, array( 'Ieteiktie produkti', 'Specials' ) ) ) { ... } Šādi būs stipri ērtāk vēlāk pievienot tekstus klāt ( vai noņemt nost ). Ideāli, Kurpirkt, Salidzini katalogiem kods gatavs. Tagat tik jāuztaisa, lai ir kā magento modulis. Quote Link to comment Share on other sites More sharing options...
rpr Posted January 30, 2013 Report Share Posted January 30, 2013 normāls lēciens no if statementa uz magento! ;) Quote Link to comment Share on other sites More sharing options...
F3llony Posted January 30, 2013 Report Share Posted January 30, 2013 (edited) Apmēram šādi, tik pārbaudi, vai nosaukums ir pareizais: //Action if( $catfull != 'featured' ) { echo "<item>"; echo "<name>".$product_type." ".$name."</name>"; echo "<link>".$url."</link>"; echo "<price>".$price."</price>"; echo "<image>".$img."</image>"; echo "<category_full>".$catfull."</category_full>"; echo "<category_link>".$caturl."</category_link>"; echo "<in_stock>".(int)$qty."</in_stock>"; echo "</item>"; } Negribu izklausīties piekasīgs, bet pamatīgi cērtas acīs - Dubultpēdiņas Dubultpēdiņas un string->var konkatenācija Vesela kaudze ar echo. Šis noteikti ir ciklā? //Action //foreach/while if( $catfull != 'featured' ) { $buf .= '<item> <name>'.$product_type.$name.'</name> <link>'.$url.'</link> <price>'.$price.'</price> <image>'.$img.'</image> <category_full>'.$catfull.'</category_full> <category_link>'.$caturl.'</category_link> <in_stock>'.(int)$qty.'</in_stock> </item>'; } //endforeach/endwhile echo $buf; Edited January 30, 2013 by F3llony Quote Link to comment Share on other sites More sharing options...
codez Posted January 30, 2013 Report Share Posted January 30, 2013 Ja jau iet tālāk, tad vēl labāk uzreiz rakstīt šādi, lai IDE smuki iekrāso tagus un parāda sintakses kļūdas, ja tādas rodās xmlā. if( $catfull != 'featured' ) { ?> <item> <name><?php echo $product_type." ".$name; ?></name> <link><?php echo $url; ?></link> <price><?php echo $price; ?></price> <image><?php echo $img; ?></image> <category_full><?php echo $catfull; ?></category_full> <category_link><?php echo $caturl; ?></category_link> <in_stock><?php echo (int)$qty; ?></in_stock> </item> <?php } Quote Link to comment Share on other sites More sharing options...
F3llony Posted January 30, 2013 Report Share Posted January 30, 2013 Nu pie katra pieprasījuma raustīt interpretātoru tikai lai vienu reizi pārbaudītu sintaksi arī nav gluži prāta darbs... 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.