Jump to content

[SOLVED] Help with this order


timmah1

Recommended Posts

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

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 />"; 

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.