I have this code i created and there are 2 entries in the Database Table however on the main page it is only showing 1 entry the PHP script is pretty complicated and involves using a few While Loops thru a number of DB tables but looking for help to get a limit of 5 transactions showing on the main page
this is the data being used to output the players, draftpicks (d), goalies (g), and prospects (p)
Code is as follows:
echo '<h2>RECENT TRANSACTIONS:</h2>';
$stmt = $conn->prepare("SELECT Team1, Team2, players1, players2, Details FROM transactions");
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
while($rows = $result->fetch_assoc()) {
$team1 = $rows['Team1'];
$players1 = $rows['players1'];
$details = $rows['Details'];
$tradearray = explode(",", $players1);
$trade = array($tradearray);
$stmt3 = $conn->prepare("SELECT abbre FROM teams WHERE number=?");
$stmt3->bind_param("i", $team1);
$stmt3->execute();
//fetching result would go here, but will be covered later
$result2 = $stmt3->get_result();
while($row3 = $result2->fetch_assoc()) {
$team_1 = $row3['abbre'];
}
for ($i=0; $i < count($trade); $i++){
foreach ($trade[$i] as $line) {
if (stripos($line, "p") !== false) {
$prospects = (intval(trim($line, "p")));
$stmt = $conn->prepare("SELECT Player FROM prospects WHERE id=?");
$stmt->bind_param("i", $prospects);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
while($rows = $result->fetch_assoc()) {
$val = $rows['Player'];
$spect = array($val);
}
} elseif (stripos($line, "d") !== false){
$draftpicks = (intval(trim($line, "d")));
$stmt = $conn->prepare("SELECT Own_by_Team, Round, Year FROM draftpicks WHERE id=?");
$stmt->bind_param("i", $draftpicks);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
$counter = 0;
while($rows = $result->fetch_assoc()) {
$team2 = $rows['Own_by_Team'];
$div = $conn->prepare("SELECT abbre FROM teams WHERE number = ?");
$div->bind_param("i", $rows['Own_by_Team']);
$div->execute();
//fetching result would go here, but will be covered later
$result1 = $div->get_result();
while($row1 = $result1->fetch_assoc()) {
$pick1ownedby = $row1['Own_by_Team'];
$abbre = $row1['abbre'];
if ($rows['Round'] == 1) {
$draft1 = array('First Round Pick');
} elseif ($rows['Round'] == 2) {
$draft2 = array('Second Round Pick');
} elseif ($rows['Round'] == 3) {
$draft3 = array('Third Round Pick');
}
}
}
} elseif (stripos($line, "g") !== false) {
$goalies = (intval(trim($line, "g")));
$stmt = $conn->prepare("SELECT Name FROM goalies WHERE id=?");
$stmt->bind_param("i", $goalies);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
while($rows = $result->fetch_assoc()) {
$goaliename = $rows['Name'];
$goalie = array($goaliename);
}
} else {
$stmt = $conn->prepare("SELECT Name FROM players WHERE Number=?");
$stmt->bind_param("i", $line);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
$counter = 0;
while($rows = $result->fetch_assoc()) {
$name = $rows['Name'];
$player = array($name);
}
}
}
}
echo '<table id="transactions"><tr><td><a href='.$team_1.'.php" target="_blank"><img src="images/'.$team_1.'.gif"></a></td><td>';
$spectlength = count($spect);
for($x = 0; $x < $spectlength; $x++) {
echo $spect[$x];
if ($spect[$x] <> '') {
echo "<br>";
}
}
$draft1length = count($draft1);
for($x = 0; $x < $draft1length; $x++) {
echo '<img src="images/'.$abbre.'.gif"></a>'; echo $draft1[$x];
if ($draft1[$x] <> '') {
echo '<br>';
}
}
$draft2length = count($draft2);
for($x = 0; $x < $draft2length; $x++) {
echo '<img src="images/'.$abbre.'.gif"></a>'; echo $draft2[$x];
if ($draft2[$x] <> '') {
echo '<br>';
}
}
$draft3length = count($draft3);
for($x = 0; $x < $draft3length; $x++) {
echo '<img src="images/'.$abbre.'.gif"></a>'; echo $draft3[$x];
if ($draft3[$x] <> '') {
echo '<br>';
}
}
$playerlength = count($player);
for($x = 0; $x < $playerlength; $x++) {
echo $player[$x];
if ($player[$x] <> '') {
echo '<br>';
}
}
$goalielength = count($goalie);
for($x = 0; $x < $goalielength; $x++) {
echo $goalie[$x];
if ($goalie[$x] <> '') {
echo '<br>';
}
}
}
$stmt = $conn->prepare("SELECT Team1, Team2, players1, players2, Details FROM transactions");
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
while($rows = $result->fetch_assoc()) {
$players2 = $rows['players2'];
$team2 = $rows['Team2'];
$trade1array = explode(",", $players2);
$trade1 = array($trade1array);
$stmt1 = $conn->prepare("SELECT abbre FROM teams WHERE number=?");
$stmt1->bind_param("i", $team2);
$stmt1->execute();
//fetching result would go here, but will be covered later
$result1 = $stmt1->get_result();
while($rows1 = $result1->fetch_assoc()) {
$team_2 = $rows1['abbre'];
}
for ($i=0; $i < count($trade1); $i++){
foreach ($trade1[$i] as $line) {
if (stripos($line, "p") !== false) {
$prospects1 = (intval(trim($line, "p")));
$stmt = $conn->prepare("SELECT Player FROM prospects WHERE id=?");
$stmt->bind_param("i", $prospects1);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
while($rows = $result->fetch_assoc()) {
$val1 = $rows['Player'];
$spect1 = array($val1);
// and add two more values to the begin of the fruit array
}
} elseif (stripos($line, "d") !== false){
$draftpicks1 = (intval(trim($line, "d")));
$stmt = $conn->prepare("SELECT Own_by_Team, Round, Year FROM draftpicks WHERE id=?");
$stmt->bind_param("i", $draftpicks1);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
$counter = 0;
while($rows = $result->fetch_assoc()) {
$pickownedby = $rows['Own_by_Team'];
$div = $conn->prepare("SELECT abbre FROM teams WHERE number = ?");
$div->bind_param("i", $rows['Own_by_Team']);
$div->execute();
//fetching result would go here, but will be covered later
$result1 = $div->get_result();
while($row1 = $result1->fetch_assoc()) {
$abbre1 = $row1['abbre'];
if ($rows['Round'] == 1) {
$draft4 = array('First Round Pick');
} elseif ($rows['Round'] == 2) {
$draft5 = array('Second Round Pick');
} elseif ($rows['Round'] == 3) {
$draft6 = array('Third Round Pick');
}
}
}
} elseif (stripos($line, "g") !== false) {
$goalies1 = (intval(trim($line, "g")));
$stmt = $conn->prepare("SELECT Name FROM goalies WHERE id=?");
$stmt->bind_param("i", $goalies1);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
while($rows = $result->fetch_assoc()) {
$goaliename1 = $rows['Name'];
$goalie1 = array($goaliename1);
}
} else {
$stmt = $conn->prepare("SELECT Name FROM players WHERE Number=?");
$stmt->bind_param("i", $line);
$stmt->execute();
//fetching result would go here, but will be covered later
$result = $stmt->get_result();
$counter = 0;
while($rows = $result->fetch_assoc()) {
$name1 = $rows['Name'];
$player1 = array($name1);
}
}
}
}
echo '</td><td><a href='.$team_2.'.php target="_blank"><img src="images/'.$team_2.'.gif"></a></td><td>';
$spect1length = count($spect1);
for($x = 0; $x < $spect1length; $x++) {
echo $spect1[$x];
if ($spect1[$x] <> '') {
echo "<br>";
}
}
$draft4length = count($draft4);
for($x = 0; $x < $draft4length; $x++) {
echo '<img src="images/'.$abbre1.'.gif"></a>'; echo $draft4[$x];
if ($draft4[$x] <> '') {
echo '<br>';
}
}
$draft5length = count($draft5);
for($x = 0; $x < $draft5length; $x++) {
echo '<img src="images/'.$abbre1.'.gif"></a>'; echo $draft5[$x];
if ($draft5[$x] <> '') {
echo '<br>';
}
}
$draft6length = count($draft6);
for($x = 0; $x < $draft6length; $x++) {
echo '<img src="images/'.$abbre1.'.gif"></a>'; echo $draft6[$x];
if ($draft6[$x] <> '') {
echo '<br>';
}
}
$player1length = count($player1);
for($x = 0; $x < $player1length; $x++) {
echo $player1[$x];
if ($player1[$x] <> '') {
echo '<br>';
}
}
$goalie1length = count($goalie1);
for($x = 0; $x < $goalie1length; $x++) {
echo $goalie1[$x];
if ($goalie1[$x] <> '') {
echo '<br>';
}
}
echo '</td></tr><tr><td colspan=4>'.$details.'</td></tr>';
}
echo'</table>';
$stmt->close();
?>
I know the majority of code works but am confused why its showing only one transaction as follows:
Any help would be appreciated thanks
If you need to know where some of the {} starts and ends i can forward that in a message
Thanks