Some of the numbers were wrong, not that it really matters, but the corrected questions is
I have a very simple mysql table which lists a number of record IDs and then has one field which lists all related record IDs, eg:
RecordID | Related
006 | 357, 440, 563, 564r, 564v, 603, 745r, 745v
I'd like to pull up the Related Ids and split them into individual numbers so I can put in a hyperlink to each one.
So, this is the simple way to extract data:
$query = "select * from records";
$result = mysql_query($query) or die("Couldn't execute query");
while ($row= mysql_fetch_array($result)) {
$RecordID = $row["RecordID"];
$Related = $row["Related"];
echo "<b>RecordID:</b> $RecordID<b> Related records:</b> $Related<br>";
}
I have now discovered that
while ($row= mysql_fetch_array($result)) {
$RecordID = $row["RecordID"];
$chars = preg_split('/, /', $row['Related'], -1, PREG_SPLIT_OFFSET_CAPTURE);
print_r ($chars);
outputs
Array (
[0] => Array ( [0] => 357 [1] => 0 )
[1] => Array ( [0] => 440 [1] => 4 )
[2] => Array ( [0] => 563 [1] => 9 )
[3] => Array ( [0] => 564r [1] => 14 )
[4] => Array ( [0] => 564v [1] => 20 )
[5] => Array ( [0] => 603 [1] => 26 )
[6] => Array ( [0] => 745r [1] => 31 )
[7] => Array ( [0] => 745v [1] => 37 ) )
instead of the list
[357, 440, 563, 564r, 564v, 603, 745r, 745v]
So there is progress.
Next question, how do I make the individual arrays into just their numbers?
I already solve the problem by having two tables, that's what I'm trying to improve, cutting down all the duplication of data input.