I am writing a wrestling promoter sim type game and am stuck on how to do something fairly common.
The page in question displays information pulled from multiple MySQL tables. As it stands everything works on this page except I’m not sure how to create a list of all rows in the “moves” table that match the wrestler. Here’s the code:
$league = $_GET['league'];
$wrestler = $_GET['wrestler'];
require_once("dbc.php");
$sql = "select roster_singles.*, roster_tag_teams.team_name, moves.move_name
from roster_singles
inner join roster_tag_teams
on (roster_singles.tag_team = roster_tag_teams.team_id and roster_singles.wrestler_id = '".$wrestler."')
inner join moves
on (roster_singles.wrestler_id = moves.wrestler_id and moves.wrestler_id = '".$wrestler."')";
$result = $mysqli->query($sql);
$row = $result -> fetch_assoc();
printf("<p><center><h2>%s</h2></center><br><br>", $row['ring_name']);
printf("<p><h3>Vital Info</h3><br><br>");
printf("<p><b>Name:</b> %s<br>", $row['ring_name']);
printf("<b>Location:</b> %s<br>", $row['location']);
printf("<b>Height:</b> %s<br>", $row['height']);
printf("<b>Weight:</b> %s<br>", $row['weight']);
printf("<b>Entrance Music:</b> %s<br>", $row['music']);
switch ($row['status']) {
case "a":
$status = "Active";
break;
case "i":
$status = "Injured";
break;
case "x":
$status = "Inactive";
break;
default:
$status = "Unknown";
break;
}
printf("<b>Status:</b> %s<br>", $status);
printf("<b>Tag-Team:</b> %s<br>", $row['team_name']);
printf("<p><h3>Moves</h3><br><br>");
printf("<p><ul>");
while($row = $result->fetch_assoc()) {
printf("<li>%s (%s)", $row['move_name'], $row['description']);
}
printf("</ul>");
}
The moves table for each wrestler will have a minimum of one move per wrestler, but can have an unlimited number. However, the above code only shows the first matching row. I’m not sure how to get it to list one row per move. Any guidance on this problem, or my coding in general is appreciated. Thanks!