Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
07-24-2007, 06:19 AM #1
- Join Date
- Jul 2006
- Thanked 0 Times in 0 Posts
Making three linked tables into a 3 dimensional array
I want to make the result of 3 tables linked through foreign keys into a 3-dimensional array that reflects their relationship without repetition and without having to call the database more three times. I know I'm doing a couple of things wrong, one thing for instance is initializing a variable at the end of the loop to remember the previous value s that it does not repeat itself, surely there must be a more elegant way to go about this, but I'm lost and I've been stuck on this all day.
here's the infamous loop:
$select_kcg = "SELECT * FROM kingdoms, castles, guards WHERE kingdoms.kingdomId=$mykingdom AND castles.kingdom_id=$mykingdom AND castles.castle_id=guards.castleId";
$mykingdom_selected = mysql_query($select_kcg) or die('Query failed: ' . mysql_error());
$castles = array();
$castle = array();
$mykingdom_king = $mykingdom["kingdom_king"];
$mykingdom_des = $mykingdom["kingdom_description"];
$castle_guards = array();
Array =>Array (=>"Castle Rock",=>King Hendrix,=>Made of Sand, =>Array(=>Timothy,=> Thomas,=>Kurt))) Array  ...
Array =>Array (['castle_name']=>"Castle Rock",['castle_king']=>King Hendrix,['castle_description']=>Made of Sand, ['castle_guards']=>Array(=>Timothy,=> Thomas,=>Kurt))) Array  ...