Jump to content

While loop not outputting array as expected


Vel

Recommended Posts

I am trying to load all rows from a table in a database into a table on a webpage. I cannot understand why the following code does not work:

<?php ...
echo "You are currently in a fleet. The details of the fleet are below.<br>";
$fleetName = $_SESSION['charFleetName'];
$sqlFleetDetails = "SELECT * FROM `$fleetName`";
$queryFleetDetails = mysql_query($sqlFleetDetails);
echo "<table>";
echo "<tr>";
	echo "<th>Pilot</th>";
	echo "<th>Ship</th>";
	echo "<th>Type</th>";
echo "</tr>";
while($rowFleetDetails = mysql_fetch_array($queryFleetDetails)) {
$charId = $rowFleetDetails['charId'];
$charName = $rowFleetDetails['charName'];
$shipHull = $rowFleetDetails['shipHull'];
$shipType = $rowFleetDetails['shipType'];
echo "<tr>";
	echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>";
	echo "<td>" . $shipHull . "</td>";
	if($shipType == 1)
		echo "<td>Logistics</td>";
	if($shipType == 2)
		echo "<td>DPS Boat</td>";
	if($shipType == 3)
		echo "<td>Sniper 120Km+</td>";
	if($shipType == 4)
		echo "<td>Off-grid Booster</td>";
echo "</tr>";
}
echo "</table><br>";

 

I originally had the $rowFleetDetails['charId'] and others in the echo instead of loading them into variables then echoing the variables but changed it to see if that was working, neither is. If I add an extra line outside of the while loop to echo the output of the array then the information is displayed fine, so I know that the information is being transferred from the table into the array correctly, but why is it not outputting properly in the While loop?

Link to comment
Share on other sites

Source code shows it should be showing correctly. I didn't think to check that hehe. I guess it's a browser issue then, it's being run in a in-game browser in a game called Eve Online.

<!DOCTYPE HTML> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Shield Fleet :: Home</title> 
</head> 

<body>You are currently in a fleet. The details of the fleet are below.<br><table><tr><th>Pilot</th><th>Ship</th><th>Type</th></tr><tr><td><a href="#" onClick="CCPEVE.showInfo{1377, 359320675}>StyphonUK</a></td><td>Nightmare</td><td>DPS Boat</td></tr></table><br><a href="fc.php">Fleet Command Page</a></body> 
</html>

Link to comment
Share on other sites

I think the issue is to do with the onClick attribute

... <a href="#" onClick="CCPEVE.showInfo{1377, 359320675}>StyphonUK</a> ...

Notice you have left of the closing double quote after the } and before the >. That could be the issue.

 

Change

		echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>";

to

		echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}\">" . $charName . "</a></td>";

Link to comment
Share on other sites

I think the issue is to do with the onClick attribute

... <a href="#" onClick="CCPEVE.showInfo{1377, 359320675}>StyphonUK</a> ...

Notice you have left of the closing double quote after the } and before the >. That could be the issue.

 

Change

		echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>";

to

		echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}\">" . $charName . "</a></td>";

Indeed it was. Thanks a lot :).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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