tidalik Posted June 14, 2006 Share Posted June 14, 2006 I have written a page that shows offspring and offspring of that offspring (and so on). The page I have written just outputs 3 generations and I would like to be able to pass the number of generations to the file and output the offspring upto that specified generations.I have used arrays, and I admit I am not to good with arrays but managed to get it to work.So problem lies with putting this all into a loop for the generations - can I plug an array back into itself??The page I have is here:[a href=\"http://www.lowchenworld.com/health/reverse_old.php?name=Tilcha%20Fashions%20Pride\" target=\"_blank\"]http://www.lowchenworld.com/health/reverse...ashions%20Pride[/a]and the messy code is here:[code]$Gens = $_GET[gens];$name = $_GET[name];//connect to the databaseinclude_once (''); //log in to databasefunction getOffspring ($name){ // query db to get results using $name $query1 = "select name from ped where sire = '$name' OR dam = '$name'"; $result1 = mysql_db_query ("", $query1); if ($result1) { $numOfRows = mysql_num_rows ($result1); for ($i = 0; $i < $numOfRows; $i++){ $offspring[$i] = mysql_result ($result1, $i, "name"); } if ($offspring){ return $offspring; } else { return false; }} else { echo ' <div id="maincontent">\n<center>\n <h3>'; echo $name; echo 'does not have any offspring</h3>'; echo '</font></div>'; mysql_close (); include ('footer.inc'); die;}}if (!$Gens){ $Gens = 2;}echo '<div id="maincontent"><center><h3>';echo $name;echo '</h3>';;//for ($k = 0; $k < $Gens; $k++){$name = addslashes($name);$get = getOffspring ($name);for ($l = 0; $l < count($get); $l++){$getget[$l] = getOffspring ($get[$l]);}//$numofget = (count($getget) + count($get));$numofget = 0;for ($l = 0; $l < count($get); $l++){ for ($y = 0; $y < count($getget[$l]); $y++){ $numofget++; } }echo '<table CELLSPACING="1" CELLPADDING="5" border="1"><tr><td ROWSPAN=';echo $numofget;echo '>Reverse pedigree of:<br>'; echo $name;echo '</td>';for ($l = 0; $l < count($get); $l++){ echo '<td rowspan='; echo count($getget[$l]); echo '><a href="reverse_old.php?name='; echo $get[$l]; echo '">'; echo $get[$l]; echo '</a> </td>'; $getget[$l] = getOffspring ($get[$l]); echo '<td>'; echo '<a href="reverse_old.php?name='; echo $getget[$l][0]; echo '">'; echo $getget[$l][0]; echo '</a></td></tr>'; for ($y = 1; $y < count($getget[$l]); $y++){ echo '<tr><td>'; echo '<a href="reverse_old.php?name='; echo $getget[$l][$y]; echo '">'; echo $getget[$l][$y]; echo '</a></td></tr>'; } }echo '</table>';//}echo '</font></div>';mysql_close ();include ('footer.inc');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11937-multi-dimentional-arrays/ Share on other sites More sharing options...
joquius Posted June 14, 2006 Share Posted June 14, 2006 uhh dunno what's in the code, but if you want to get multidimensional arrays it's:[code]<?foreach ($array as $x => $_array){ foreach ($_array as $y => $value) { echo "($x,$y) position is equal to $value"; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11937-multi-dimentional-arrays/#findComment-45400 Share on other sites More sharing options...
tidalik Posted June 14, 2006 Author Share Posted June 14, 2006 I really didn't explain myself well, my first attempt was lost due with the 'quote' tag (highlight something and press the quote button and you lose the lot...).This is basically what should happen:1. Recieve a Name via $_GET and Number of Generations2. Find Offspring of Name, save it to Array[]3. Find the Offspring of Array[] Name, save it to Array[][]4. Find the Offspring of Array[][], save it to Array[][][]-and on and on until the # of Generations are complete-Then I must find the total number of names in the final rotation, and output the names into a HTML table.I can get the info into arrays (including multi-dimentional arrays) but not in a loop system which would allow me to pass the # of generations via $_GET.So how do I go about setting up the arrays if I don't know the # of Generations needed until the script is run? Quote Link to comment https://forums.phpfreaks.com/topic/11937-multi-dimentional-arrays/#findComment-45460 Share on other sites More sharing options...
tidalik Posted June 18, 2006 Author Share Posted June 18, 2006 Anyone have any ideas about building Multi-demintional arrays using loops? Or should I be looking at this differently? Quote Link to comment https://forums.phpfreaks.com/topic/11937-multi-dimentional-arrays/#findComment-46926 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.