Vel Posted May 8, 2011 Share Posted May 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/ Share on other sites More sharing options...
wildteen88 Posted May 8, 2011 Share Posted May 8, 2011 What do you mean by not outputting properly in the While loop? Is it not parsing your variables or is the HTML table not displaying properly Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/#findComment-1212433 Share on other sites More sharing options...
Vel Posted May 8, 2011 Author Share Posted May 8, 2011 The HTML table is empty where it should be displaying the details of members in the fleet. Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/#findComment-1212434 Share on other sites More sharing options...
wildteen88 Posted May 8, 2011 Share Posted May 8, 2011 Your code is correct. There are no problems I can see which could trigger an error. If you go to your page and right click view source what html is being generated Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/#findComment-1212437 Share on other sites More sharing options...
Vel Posted May 8, 2011 Author Share Posted May 8, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/#findComment-1212438 Share on other sites More sharing options...
Vel Posted May 8, 2011 Author Share Posted May 8, 2011 Just seen it. Missed a " in the href tag. EDIT: Yep, that solved it, working fine now. Damn quotation mark. Thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/#findComment-1212439 Share on other sites More sharing options...
wildteen88 Posted May 8, 2011 Share Posted May 8, 2011 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/#findComment-1212440 Share on other sites More sharing options...
Vel Posted May 8, 2011 Author Share Posted May 8, 2011 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 . Quote Link to comment https://forums.phpfreaks.com/topic/235864-while-loop-not-outputting-array-as-expected/#findComment-1212441 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.