Jump to content

Recommended Posts

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
     
}

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/
Share on other sites

 

 

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.

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305226
Share on other sites

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, '&=')));
?>

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305231
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/61338-php-array-values/#findComment-305259
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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