String Help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
theoph
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA

String Help

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

strings and arrays

Post 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
theoph
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA

Post 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
Post Reply