Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split multiple data from array? strpos()?

Status
Not open for further replies.

scriggs

IS-IT--Management
Jun 1, 2004
286
GB
I have some code which takes field from a database and puts them in an array, split by a | character.

Code:
$files[$i] = odbc_result($odbc_rs,'ClientCode') . " | " . odbc_result($odbc_rs,'ReportName');

I use this data in one long string to search for data in a simple search engine.

To display the results I use the following code to extract the code and put on the screen:

Code:
substr($value,0,strpos($value," | "))

This all works fine (but if you have better way let me know!) What I need to do now is extract the second field, third field, etc.

How can I adapt code to pick which entry I need.....
 
use this instead
Code:
$i = "" ; // element of the files array = row number
echo "<table width=\"80%">";
foreach ($files as $value):
 $fieldsfromrow=explode(" | ", $value);
 echo "<tr>";
 foreach ($fieldsfromrow as $val):
  echo "<td>$val</td>";
 endforeach;
 echo "</tr>";
endforeach;
echo "</table>";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top