timmah1 Posted December 27, 2008 Share Posted December 27, 2008 I've been trying for awhile now to try and get this to go in the correct order i need it too. It puts them in the correct order if all 6 sports are in the database, but if there are less than 6, I get the error Warning: Invalid argument supplied for foreach() in /home/vegas/public_html/core/admin/showPicks1.php on line 66 Can anyone figure out how to not show the error if there is less than 6? Here is the code while($a = mysql_fetch_assoc($q)) { $packages; if( $a['package'] == "ult" ) $packages[0] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "sngl" ) $packages[1] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "mnth" ) $packages[2] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "ssn" ) $packages[3] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "po" ) $packages[4] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "spl" ) $packages[5] = array( $a['package'] => $a['picks'] ); for( $i = 0; $i < count($packages); $i++ ) { foreach($packages[$i] as $key => $value) { switch ($key) { case "ult": $key1 = "Ultimate Lock Pick Package"; break; case "sngl": $key1 = "Single Pick Package"; break; case "mnth": $key1 = "Month Package"; break; case "ssn": $key1 = "Season Package"; break; case "po": $key1 = "Playoffs Package"; break; case "spl": $key1 = "Special Package"; break; default: $key1 = "Nothing"; break; } } } echo "<strong>" . $key1 . "</strong><br />".nl2br($value)."<br /><br />"; [/code Thank you in advance Link to comment https://forums.phpfreaks.com/topic/138542-solved-help-with-this-order/ Share on other sites More sharing options...
Psycho Posted December 27, 2008 Share Posted December 27, 2008 I thinkt he problem is that you are hard coding the indexes for the array - so if one is missing the for loop will try to reference an element that does not exist. Try this: while($a = mysql_fetch_assoc($q)) { $packages; if( $a['package'] == "ult" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "sngl" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "mnth" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "ssn" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "po" ) $packages[] = array( $a['package'] => $a['picks'] ); if( $a['package'] == "spl" ) $packages[] = array( $a['package'] => $a['picks'] ); for( $i = 0; $i < count($packages); $i++ ) { foreach($packages[$i] as $key => $value) { switch ($key) { case "ult": $key1 = "Ultimate Lock Pick Package"; break; case "sngl": $key1 = "Single Pick Package"; break; case "mnth": $key1 = "Month Package"; break; case "ssn": $key1 = "Season Package"; break; case "po": $key1 = "Playoffs Package"; break; case "spl": $key1 = "Special Package"; break; default: $key1 = "Nothing"; break; } } } echo "<strong>" . $key1 . "</strong><br />".nl2br($value)."<br /><br />"; Link to comment https://forums.phpfreaks.com/topic/138542-solved-help-with-this-order/#findComment-724365 Share on other sites More sharing options...
timmah1 Posted December 27, 2008 Author Share Posted December 27, 2008 Perfect mjdamato! Thank you so much Link to comment https://forums.phpfreaks.com/topic/138542-solved-help-with-this-order/#findComment-724509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.