Need help extracting data and syncing data from 2 different

Here is my problem. I need to sync up data from 2 separate databases.
The data in the first database is stored in one column, here is an example of the data: 3214, 3478, 3100
These number are the idProduct Primary Key from the Products table of the second database.

I need to separate the numbers the coma is the delimiter. each 4 digit number is a different product number from the second database.

The site is currently done in ASP and access database. I converted the databases to mySQL and redoing the site in PHP.

Here is the code from the asp page is it possible to convert this to PHP?

’ the regular expression will be used to filter out numbers from the commas
Set REsupplies = New RegExp

With REsupplies
.Pattern = “[0-9][0-9][0-9][0-9]”
.Global = True
End With

do until rs.eof or rs.bof

Set expressionmatch = REsupplies.Execute(varSupplies)
if expressionmatch.Count > 0 Then
  For Each expressionmatched in expressionmatch
    varIdProduct = expressionmatched.Value
    rs3.filter = "idproduct = "&varIdProduct
    varProductName = rs3("description")
    <a href="ct_viewItem.asp?idProduct=<%=varIdProduct%>"><%=varProductName%>[/url]

end if    

I’ve gotten this far but now I’m not sure how to make each number pull up the records from the other database.

<?php $token = strtok ("3213,1234,5454,3100",", "); while($token){ print($token . " "); $token = strtok(", "); } ?>

I need to make each 4 digit number pull up the record for the product in the second database.

instead of printig the token u may use it inside a mysql_query
$token = strtok (“3213,1234,5454,3100”,", “);
$result=mysql_query('SELECT … WHERE idProduct=”.$token);
//do whatever u wanna do with the result
$token = strtok(", ");

If all the values are stored in a single field, you could use explode() to turn it into an array and then just run through a loop using mysql_query() to get the desired action.

$my_string = “my1, my2, my3”;
$my_array = explode(",", $my_string);

for($i = 0; $i < count($my_array); $i++)

   $q = "SELECT...WHERE idProduct = '$my_array[$i]'";
   mysql_query($q) or die("Error....");


What you’re looking for is what Ragster points out.

I have a question though: why use comma-delimited values in a database? If you want to keep scalability in mind, you can just use a 1:N or M:N relation table.

This was an Access Database that I converted over to mySQL, and I don’t want to retype in the 4000 rows of data.

I got it, Thanks for the help

		$token = strtok ($row_rsGallery['supplies'],", ");
		$query = sprintf("SELECT * FROM products WHERE idProduct = %s AND active = -1",mysql_real_escape_string($token));
		$result = mysql_query($query);
		mysql_query($query) or die("No Products Found"); 
		while ($row = mysql_fetch_assoc($result)){
			echo '<a href="shop/product.php?idProduct=' . $row['idProduct'] . '" class="" title="' . $row['description'] . '">' . $row['description'] . '</a><br>';
		$token = strtok(", ");
Sponsor our Newsletter | Privacy Policy | Terms of Service