Steven Posted April 21, 2009 Share Posted April 21, 2009 Hi all,I'm able to connect to a DB and fetch data and present it on an xhtml page. However, now I am trying to get all of the rows from a particular table to fill out a table, and I'm not sure how to do it. I was able to get one row to be entered, but it wouldn't continue. here's my code.Markup <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><?php include("getplayers.php"); ?><table width="100%" border="1"> <tr> <td>ID</td> <td>No.</td> <td>First Name</td> <td>Last Name</td> <td>Nationality</td> <td>Age</td> <td>Position</td> <td>Strength</td> <td>Stamina</td> <td>Skating</td> <td>Speed</td> <td>Checking</td> <td>Hitting</td> <td>Work Rate</td> <td>Positioning</td> <td>Passing</td> <td>Puck Control</td> <td>Deking</td> <td>Slap Shot</td> <td>Wrist Shot</td> <td>Face-Off</td> </tr> </tr> <tr> <td><?=$id?></td> <td><?=$no?></td> <td><?=$firstname?></td> <td><?=$lastname?></td> <td><?=$nationality?></td> <td><?=$age?></td> <td><?=$position?></td> <td><?=$strength?></td> <td><?=$stamina?></td> <td><?=$skating?></td> <td><?=$speed?></td> <td><?=$checking?></td> <td><?=$hitting?></td> <td><?=$workrate?></td> <td><?=$positioning?></td> <td><?=$passing?></td> <td><?=$puckcontrol?></td> <td><?=$deking?></td> <td><?=$slapshot?></td> <td><?=$wristshot?></td> <td><?=$faceoff?></td> </tr></table></body></html> getplayers.php <?php$con = mysql_connect("***","***","***");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("rpgx2b9_dukes", $con);$result = mysql_query("SELECT * FROM th_players");while($row = mysql_fetch_array($result)) { $id = $row['ID']; $no = $row['No']; $firstname = $row['First Name']; $lastname = $row['Last Name']; $nationality = $row['Nationality']; $age = $row['Age']; $position = $row['Position']; $strength = $row['Strength']; $stamina = $row['Stamina']; $skating = $row['Skating']; $speed = $row['Speed']; $checking = $row['Checking']; $hitting = $row['Hitting']; $workrate = $row['Work Rate']; $positioning = $row['Positioning']; $passing = $row['Passing']; $puckcontrol = $row['Puck Control']; $deking = $row['Deking']; $slapshot = $row['Slap Shot']; $wristshot = $row['Wrist Shot']; $faceoff = $row['Face-Off'];}mysql_close($con);?> Thanks in advance! Link to comment Share on other sites More sharing options...
jeffman Posted April 21, 2009 Share Posted April 21, 2009 What's happening now is that when "getplayers.php" gets included, the entire while loop gets iterated. THEN the last row of your table gets plugged into the table cells. What you need to do is integrate the table-row construction with the while loop, so that one <tr> gets written during each iteration of the loop. So part of that loop might look like this: $str = '';while($row = mysql_fetch_array($result)) { $str .= '<tr>'; $str .= '<td>' . $row['ID'] . '</td>'; $str .= '<td>' . $row['No'] . '</td>'; . . . $str .= '</tr>';}echo $str; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.