Jump to content

Help with an array


Julian

Recommended Posts

Hello guys.

 

With this portion of code I'm obtaining perfectly the info I want to show on my page.  Originally the script return one field from the database.  Now my client want to show also a picture.  Which is on the same table, my problem is if I insert another foreach I get all the pictures on the table.  I'm looking for a way I can call the $pic0 within the foreach script.

$count2 = 0;
	$new_type_array2 = array();
		while (list($id_grupo, $grupo, , , $pic0) = mysql_fetch_row($grupos)) {
			$new_type_array2[$id_grupo] = $grupo;
			$new_type_array3[$id_grupo] = $pic0;
		}

	foreach ($new_type_array2 as $typeid2 => $desc2){

		//foreach ($new_type_array3 as $image => $pic){

			if (in_array($typeid2, $db_array)){

				echo 	'<tr>
							<td><img src="../Images/pages/' . $pic . '" alt="" border="0" /></td>
								<td align="left"><span class="class10"><a class="linkcolor2" href="../grupos/grupos.php?id_grupo=' . $typeid2 . '">';
				echo $desc2;
				echo 		'</a></td>
						</tr>';
			}
		//}
	}

 

Thanks for the help.

 

Link to comment
https://forums.phpfreaks.com/topic/149901-help-with-an-array/
Share on other sites

couldnt you do something like this:

 

$count2 = 0;
	$new_type_array2 = array();
		while (list($id_grupo, $grupo, , , $pic0) = mysql_fetch_row($grupos)) {
			$new_type_array2[$id_grupo] = $grupo;
			$new_type_array3[$id_grupo] = $pic0;
		}

                         $count_pictures = 0; //initialize the count to zero

	foreach ($new_type_array2 as $typeid2 => $desc2){


			if (in_array($typeid2, $db_array)){

				echo 	'<tr>
							<td><img src="../Images/pages/' . $new_type_array3[$count_pictures] . '" alt="" border="0" /></td>
								<td align="left"><span class="class10"><a class="linkcolor2" href="../grupos/grupos.php?id_grupo=' . $typeid2 . '">';
				echo $desc2;
				echo 		'</a></td>
						</tr>';
$count_pictures++;
			}
		//}
	}

 

I am a little lost at what you are trying to do but basically what i did was for each loop in the foreach loop i called upon the value in that array and then incremented it for the next loop. Would that help?

Link to comment
https://forums.phpfreaks.com/topic/149901-help-with-an-array/#findComment-787283
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.