aebstract Posted April 28, 2010 Share Posted April 28, 2010 foreach ( $indexL[$var] as $val ){ foreach ( $val as $key=>$final_val ){ $content .= "$key[firstname]"; } $content .= "<br>"; } Here are the results from a print_r($indexL[$var]); Array ( [0] => Array ( [firstname] => Mike [lastname] => Herring [q1] => 4.616 [q2] => 4.669 [q3] => 4.686 [regid] => 118 [eventid] => 1 ) ) Array ( [0] => Array ( [firstname] => Adam [lastname] => Garner [q1] => 5.286 [q2] => 5.286 [q3] => 5.286 [regid] => 109 [eventid] => 1 ) [1] => Array ( [firstname] => Ronnie [lastname] => Clayton [q1] => 5.219 [q2] => 5.228 [q3] => 5.228 [regid] => 155 [eventid] => 1 ) ) Array ( ) Array ( [0] => Array ( [firstname] => Terry [lastname] => McClendon [q1] => 6.998 [q2] => 6.998 [q3] => 6.998 [regid] => 83 [eventid] => 1 ) ) My output looks like: flqqqre flqqqre flqqqre flqqqre I tried to use $final_val[firstname] but it gave me odd results too. Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/ Share on other sites More sharing options...
Ken2k7 Posted April 28, 2010 Share Posted April 28, 2010 What are the bullet points? Also, why did you use a foreach loop if you're just going to display firstname all the time? Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049899 Share on other sites More sharing options...
teamatomic Posted April 28, 2010 Share Posted April 28, 2010 Try this: foreach ( $indexL[$var] as $val ){ foreach ( $val as $final_val ){ $content .= "$final_val[firstname]<br>"; } } HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049905 Share on other sites More sharing options...
aebstract Posted April 28, 2010 Author Share Posted April 28, 2010 What are the bullet points? Also, why did you use a foreach loop if you're just going to display firstname all the time? I guess they got changed to bullets, it's indexes [0] [1] etc, none of them go over 1. Here is the full array for $indexL: Array ( [4.70 Index] => Array ( [ 0 ] => Array ( [firstname] => Mike [lastname] => Herring [q1] => 4.616 [q2] => 4.669 [q3] => 4.686 [regid] => 118 [eventid] => 1 ) ) [5.30 Index] => Array ( [ 0 ] => Array ( [firstname] => Adam [lastname] => Garner [q1] => 5.286 [q2] => 5.286 [q3] => 5.286 [regid] => 109 [eventid] => 1 ) [ 1 ] => Array ( [firstname] => Ronnie [lastname] => Clayton [q1] => 5.219 [q2] => 5.228 [q3] => 5.228 [regid] => 155 [eventid] => 1 ) ) [6.00 Index] => Array ( ) [7.00 Index] => Array ( [ 0 ] => Array ( [firstname] => Terry [lastname] => McClendon [q1] => 6.998 [q2] => 6.998 [q3] => 6.998 [regid] => 83 [eventid] => 1 ) ) ) I put spaces so it wouldn't change. I plan on doing other things with the values in the array, I was just trying to get a grasp on how to control the values and so far I can't get the value. teamatomic: When I try that code, I get this output: 4.70 M H 4 4 4 1 1 5.30 Index A G 5 5 5 1 1 R C 5 5 5 1 1 6.00 Index 7.00 Index T M 6 6 6 8 1 Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049907 Share on other sites More sharing options...
Ken2k7 Posted April 28, 2010 Share Posted April 28, 2010 foreach ( $indexL[$var] as $val ){ foreach ( $val as $final_val ){ $content .= sprintf("%s <br/>", $final_val['firstname']); } } Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049909 Share on other sites More sharing options...
aebstract Posted April 28, 2010 Author Share Posted April 28, 2010 foreach ( $indexL[$var] as $val ){ foreach ( $val as $final_val ){ $content .= sprintf("%s <br/>", $final_val['firstname']); } } I get the same results as what I posted to atomic. Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049911 Share on other sites More sharing options...
Ken2k7 Posted April 28, 2010 Share Posted April 28, 2010 Could you please post the code you have? And var_dump the array for me. Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049917 Share on other sites More sharing options...
aebstract Posted April 28, 2010 Author Share Posted April 28, 2010 $query2 = mysql_query(" SELECT registrations.firstname, participants.eventid, registrations.lastname, participants.q1, participants.q2, participants.q3, participants.q1s, participants.q2s, participants.q3s, participants.q1rt, participants.q2rt, participants.q3rt, participants.regid FROM participants INNER JOIN registrations ON registrations.id = participants.regid WHERE participants.eventid = $_GET[event] AND registrations.class = '$var'") or DIE(mysql_error()); if(mysql_num_rows($query)!=0){ $indexL[$var] = array(); $indexH[$var] = array(); while($r2=mysql_fetch_array($query2)) { $var2 = substr($var,0,4); if ((($r2[q1] + $r2[q1rt]) < $var2) && (($r2[q2] + $r2[q2rt]) < $var2) && (($r2[q3] + $r2[q3rt]) < $var2)){ $indexL[$var][] = array('firstname' => "$r2[firstname]", 'lastname' => "$r2[lastname]", 'q1' => "$r2[q1]", 'q2' => "$r2[q2]", 'q3' => "$r2[q3]", 'regid' => "$r2[regid]", 'eventid' => "$r2[eventid]"); } else { $indexH[$var][] = array('firstname' => "$r2[firstname]", 'lastname' => "$r2[lastname]", 'q1' => "$r2[q1]", 'q2' => "$r2[q2]", 'q3' => "$r2[q3]", 'regid' => "$r2[regid]", 'eventid' => "$r2[eventid]"); } } } $countH = count($indexH[$var]); $countL = count($indexL[$var]); foreach ( $indexL[$var] as $val ){ foreach ( $val as $final_val ){ $content .= sprintf("%s <br/>", $final_val['firstname']); } } Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049919 Share on other sites More sharing options...
Ken2k7 Posted April 28, 2010 Share Posted April 28, 2010 Why did you store them in an array? What's wrong with just outputting the result within the while loop? Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049926 Share on other sites More sharing options...
aebstract Posted April 28, 2010 Author Share Posted April 28, 2010 I'm going to be putting them in a specific order, once I figure out how to get that information. Why all the questions instead of getting the value to display? Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049930 Share on other sites More sharing options...
aebstract Posted April 28, 2010 Author Share Posted April 28, 2010 foreach ( $indexL[$var] as $val ){ foreach ( $val as $final_val ){ $content .= "$final_val[firstname]<br>"; } } I don't see what in this would cause only the first character of each value to be returned? Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049956 Share on other sites More sharing options...
aebstract Posted April 28, 2010 Author Share Posted April 28, 2010 Winner: foreach ( $indexL[$var] as $val ){ $content .= "$val[firstname] $val[lastname] $val[q1] $val[q2]<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/200036-foreach-loop-odd-results/#findComment-1049961 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.