e1seix Posted May 5, 2008 Share Posted May 5, 2008 I have a slight problem. Using datafeeds in my website, I'm finding that one of my datafeed properites - the identifier - is a series of 6 different numbers eg. 001234. When in fact the number is as so with two zeros at the start my database automatically reverts it to just "1234" which then won't read when i use the identifier in my code to look for changes to product info etc. What simple way is there to say that if a database result is only 4 digits, stick two 0's at the start, and if it's five digits, one zero etc. so i can then redefine variable for use in searching database? any help is always appreciated Link to comment https://forums.phpfreaks.com/topic/104252-if-scenario-variable/ Share on other sites More sharing options...
flyhoney Posted May 5, 2008 Share Posted May 5, 2008 str_pad($input, 6, "0", STR_PAD_LEFT); Link to comment https://forums.phpfreaks.com/topic/104252-if-scenario-variable/#findComment-533710 Share on other sites More sharing options...
cx323 Posted May 5, 2008 Share Posted May 5, 2008 CREATE TABLE `db`.`table` ( `identifier` integer(6) ZEROFILL NOT NULL ) Link to comment https://forums.phpfreaks.com/topic/104252-if-scenario-variable/#findComment-533712 Share on other sites More sharing options...
flyhoney Posted May 5, 2008 Share Posted May 5, 2008 <?php $foo = '2342'; $foo = str_pad($foo, 6, "0", STR_PAD_LEFT); echo $foo; ?> will output: 002342 Link to comment https://forums.phpfreaks.com/topic/104252-if-scenario-variable/#findComment-533713 Share on other sites More sharing options...
e1seix Posted May 5, 2008 Author Share Posted May 5, 2008 I have tried the following code, but it doesn't appear to be working. any tips? // FRAGRANCEDIRECT $qry9 = mysql_query("UPDATE admin SET inStock='no' WHERE dataID='9'") or die(mysql_error()); $xml = simplexml_load_file('http://datafeeds.productserve.com/datafeed_products.php?user=******&password=******&mid=9&format=xml&dtd=1.2'); foreach ($xml->xpath('//prod') as $character) { $pId9 = $character->pId; $awLink9 = $character->awLink; $promo9 = $character->promo; $search9 = $character->price->search; $pId9 = str_pad($pId9, 6, "0", STR_PAD_LEFT); $result9 = mysql_query("UPDATE admin SET inStock='yes',dataDesc='$desc9',dataP='$search9',dataID='9',dataName='Fragrancedirect',dataWeb='www.fragrancedirect.co.uk',webLink='http://www.awin1.com/awclick.php?mid=9&id=74040',dataLink='$awLink9' WHERE dataID='9' AND dataCode='$pId9'") or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/104252-if-scenario-variable/#findComment-533765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.