Jump to content

While loop does not display all contents


bbram
 Share

Recommended Posts

I have 2 pages...1 one that has something like 500 checkboxes that list all of the active users in a database.  When any number of checkboxes are selected it passes the variables from the checkboxes to the next page, asking for confirmation.  

 

Right now I have the 2nd page displaying numbers for the people, but doesn't display the correct entries.

 

The code is below, hopefully it helps:

 

if(isset($_POST['Update'])) //if the update button was pressed
{
    if (isset($_POST['Player_number'])) //checks to see if any checkboxes are selected
    {
    
        //$Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items
        echo $Player_number;
        ?>
        <input type="hidden" name="<?PHP $Player_number; ?>" value="<?PHP $Player_number; ?>">
$Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items

$result = mysql_query("SELECT * FROM `players` WHERE `Player_number` = '$Player_number' ORDER BY Player_Last_Name") or die(mysql_error());

while ($row = mysql_fetch_array($result))
//while ($row = mysql_fetch_assoc($result))
 {
                // here is your data
 
                echo "FName: ".$row['Player_First_Name'];
                echo "lName: ".$row['Player_Last_Name'];
                echo "email: ".$row['player_email'];
}

foreach($_POST['Player_number'] as $row)
		{	
			$result = mysql_query("SELECT `Player_First_Name`,`Player_Last_Name`,`player_email`, `Player_number` FROM `players` WHERE `Player_number` = '$Player_number' ORDER BY Player_Last_Name") or die(mysql_error());
			$Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items
			while($rows=mysql_fetch_array($result))
			{
				echo "Player Number: ".$Player_number;
				//echo "pNumber: ".$row;
				//echo $rows['Player_First_Name'];
	?>
				<tr bgcolor='<?PHP echo $bkcolor; ?>'>
				<td width = '20%' height="20"><div align="center"><input type="hidden" name="Player_number[]" value="<?php echo $row; ?>"></div></td>
				<td width= '20%' headers="20"><div align="center"><?php echo $rows['Player_First_Name']; ?></div></td>
				<td width= '20%' headers="20"><div align="center"><?php echo $rows['Player_Last_Name']; ?></div></td>
				<td width= '20%' headers="20"><div align="center"><?php echo $rows['player_email']; ?></div></td>						
			<?PHP
			}//close of the while loop	
		}//close of the foreach loop
	}//close of if (isset($_POST['Player_number']))		
} //close of (isset($_POST['Update']
                  
                  


  My issue that it goes through the For loop that is listed above, but list the player first name X amount of times.
 

Link to comment
Share on other sites

Sorry, you are using mysql_query().  It's a waste of time for people to answer questions about mysql_  functions. 

It was listed as deprecated (which meant you should no longer create NEW CODE with those functions in 2013.  As of now, there is no supported version of PHP that has the mysql_ functions.

Convert your code to mysqli_ or better yet, PDO, and we'll look at. 

Probably your issue has to do with your lack of use of  WHERE IN ().

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • 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.