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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is this ok?

Status
Not open for further replies.

safra

Technical User
Jan 24, 2001
319
NL
Hi,

I am new to MySQL. Have to tables, basically I want to go through column 'owner1' from table 'owner' and get for each value(row) all values of column 2 in table 2 that has this value as the key and put this value in a unique javascript array.

I did this:


Code:
$result=MYSQL_QUERY("SELECT * FROM owner ORDER BY `owner1` ASC");

$i = 0;
while ($myrow = mysql_fetch_row($result)) {
	$j = 0;
	echo "group[$i]=new Array();\n";
	$what = "empty";
	echo "group[$i][0]=new Option(\"Empty\")\n"; // deal with empty array
	$cases=MYSQL_QUERY("SELECT * FROM cases WHERE owner1='$myrow[1]'");

	while ($myCases = mysql_fetch_row($cases)) {
		echo "group[$i][$j]=new Option(\"$myCases[1]\")\n";
		$j++;
	}
$i++;
}

It works but is the way I parse data from MySQL appropriate or is there a better more direct way to do this?

Thanks,
Ron
 
You can join the tables. Try something like this:
Code:
SELECT *
FROM   owner o,
       cases c 
WHERE  o.owner = c.owner1
ORDER BY o.owner,
         c.xxx;

 
Thanks, I will try that!

should I put that literally in the MySQL query and how will the output look like?
Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top