Page 1 of 1

String Help

Posted: Mon Sep 06, 2004 10:50 pm
by theoph
I working on a way to take information in a mysql record field that is comma delimited (e.g. "000001,000012") and then match it with its corresponding id number is another mysql database.

For instance the second mysql database the record ID "000001" is named "Home" and record ID "000012" is named "Work."

What I wanting to do is to have php script to display the comma delimited information and display it with the names of the records in the second mysql database.

In other words, I want to display (000001,000012) as (Home, Work).

How can I do this? I'm new to php and I'm at a lost.

Posted: Mon Sep 06, 2004 11:12 pm
by feyd
This is generally called linking, or referencing. It can be suggested to not store a comma delimited array in a table when a simpler solution is available. I'm going to assume that these comma delimited sets are attached to someone or something, where each can have access to variant numbers of these records. This is a many-to-many relationship. These set up's usually require 3 tables. 2 data tables, and a link between the two. There are a few recent threads in the database forum that talk about many-to-many relationships and their set up.

strings and arrays

Posted: Tue Sep 07, 2004 3:46 am
by phpScott
if both data sets are coming from two different db's then you will probably not be able to do the join, if they are from the same db and different tables then they joining table would be the best.

However if the first is true you will have to loop through your dataset and doing string comparrisions to match the data.

By they way it is great to be back after not having regular access for so long. :D :D

Posted: Tue Sep 07, 2004 12:32 pm
by theoph
Found a way of doing this with the following script.

Code: Select all

<?php 
	do {
		if(strpos($row_rsLaos['scell'],$row_rsCellmenu['id'])!==FALSE)
			{
				echo $row_rsCellmenu['name'].', ';
			}
		}
		while ($row_rsCellmenu = mysql_fetch_assoc($rsCellmenu));
?>
Thanks to everyone who gave me suggestions :D