maliary Posted July 23, 2007 Share Posted July 23, 2007 I am working a database retrival code and I can only obtain partial data from a string. $rows['serial_value'] is a string made of a combination of two distinct values separeted by = and & symbols. How would I obtain the two values and out put them separetly? This is the query: $depts = $db->Execute("SELECT $dbtable.serial_value,$dbtable.type,$dbtable.group_id,$table.name,$table.nr,$table.normals,$table.msr_unit FROM $dbtable,$table WHERE ($table.group_id = $dbtable.group_id) AND $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"); while($rows= $depts->FetchRow()){ $h = $rows['serial_value']; // This is a string $keywords = preg_split ("/[\=,\&]+/", "$h"); // Remove the = and & symbols in the string } Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/ Share on other sites More sharing options...
tapos Posted July 23, 2007 Share Posted July 23, 2007 Simply use $keywords = explode('&',$h) //now check the value print_r($keywords); I think this will solve your problem -- Tapos Pal Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305215 Share on other sites More sharing options...
DeadEvil Posted July 23, 2007 Share Posted July 23, 2007 $keywords = preg_replace('=','',$h); $keywords = explode('&',$keywords); print_r($keywords); Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305219 Share on other sites More sharing options...
btherl Posted July 23, 2007 Share Posted July 23, 2007 Suggestion 3: parse_str($string, &$array); print_r($array); Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305220 Share on other sites More sharing options...
maliary Posted July 23, 2007 Author Share Posted July 23, 2007 Thanks guys, But its not the split thats the problem, its after i split. for instance this is the string - &=119=-&=128=2&=129=3&=130=-&=132=-&=141=-&=152=-&=153=-&=154=-&=155=-&=186=-&=195=-&=198=-&=223=-&=226=2&=119=-&=128=-&=129=-&=130=-&=132=-&=141=-&=152 I want to display it like 119 - - 128 - 2 129 - 3 that way. Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305226 Share on other sites More sharing options...
sasa Posted July 23, 2007 Share Posted July 23, 2007 try <?php $string = '&=119=-&=128=2&=129=3&=130=-&=132=-&=141=-&=152=-&=153=-&=154=-&=155=-&=186=-&=195=-&=198=-&=223=-&=226=2&=119=-&=128=-&=129=-&=130=-&=132=-&=141=-&=152'; echo $string = str_replace('=', ' - ', str_replace('&=', "<br />\n", trim($string, '&='))); ?> Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305231 Share on other sites More sharing options...
maliary Posted July 23, 2007 Author Share Posted July 23, 2007 Hi Sasa, At the parts with numbers instead of dashes (-) It prints out this way 226-2119-- 128-2129-- It doesn't break at these parts. Could we use the array instead of the string? Just asking.. Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305242 Share on other sites More sharing options...
sasa Posted July 23, 2007 Share Posted July 23, 2007 i try with your string and output look X-Powered-By: PHP/4.4.4 Content-type: text/html 119 - -<br /> 128 - 2<br /> 129 - 3<br /> 130 - -<br /> 132 - -<br /> 141 - -<br /> 152 - -<br /> 153 - -<br /> 154 - -<br /> 155 - -<br /> 186 - -<br /> 195 - -<br /> 198 - -<br /> 223 - -<br /> 226 - 2<br /> 119 - -<br /> 128 - -<br /> 129 - -<br /> 130 - -<br /> 132 - -<br /> 141 - -<br /> 152 if you want just output this, string is OK if you want some calculation with data array is better Quote Link to comment https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305259 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.