mysql_fetch_array() error -- building player roster
Posted: Wed Jan 14, 2009 12:35 am
Hello.
I'm building a website for an online role playing game and I'm working on the player roster right now.
The player roster is a table listing basic information about players, and also a list of the characters they own.
In this case, as I am a newbie, I am using a nested while loop using a second SQL query. I am getting the error below in the section of the table where characters are listed.
I have two questions:
1) How do I fix the code so it does list the players characters?
2) Eventually, the characters will have a full character sheet built in PHP and I will need the characters names to be links to the full sheet. I don't know how to do this as I am a complete n00b.
Here is my code for the player roster:
I'm building a website for an online role playing game and I'm working on the player roster right now.
The player roster is a table listing basic information about players, and also a list of the characters they own.
In this case, as I am a newbie, I am using a nested while loop using a second SQL query. I am getting the error below in the section of the table where characters are listed.
Code: Select all
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\server\xampp\htdocs\login\player_roster.php on line 49
1) How do I fix the code so it does list the players characters?
2) Eventually, the characters will have a full character sheet built in PHP and I will need the characters names to be links to the full sheet. I don't know how to do this as I am a complete n00b.
Here is my code for the player roster:
Code: Select all
<?php
include ('dbc.php');
//calculate years of age (input string: YYYY-MM-DD)
function birthday ($birthday){
list($year,$month,$day) = explode("-",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0 || $month_diff < 0)
$year_diff--;
return $year_diff;
}
$result = mysql_query("SELECT * FROM players ORDER BY player_nick");
print "
<table width='90%'>
<tr>
<th>Player</th>
<th>Status</th>
<th>Characters</th>
<th>Gender</th>
<th>Age</th>
<th>Country</th>
<th>E-mail</th>
<th>Livejournal</th>
<th>Web Site</th>
<th></th>
</tr>";
while($row = mysql_fetch_array($result))
{
$player = $row['player_nick'];
$charlist = mysql_query("SELECT * FROM characters WHERE char_player = $player ORDER BY char_nick");
$bday = $row['player_bday'];
print "<tr><td>";
print $row['player_nick'];
print "</td><td>";
print $row['player_status'];
print "</td><td>";
while($charrow = mysql_fetch_array($charlist))
{
print $charrow['char_nick'];
print " ";
}
print "</td><td>";
print $row['player_sex'];
print "</td><td>";
print birthday($bday);
print "</td><td>";
print $row['player_country'];
print "</td><td> <a href='mailto:x";
print $row['player_email'];
print "x'>@</a></td><td>";
if ($row['player_lj'] = NULL)
{
print "</td><td>";
}
else
{
print "<a href='http://";
print $row['livejournal'];
print ".livejournal.com/'>LJ</a></td><td>";
}
if ($row['player_website'] = NULL)
{
print "</td><td>";
}
else
{
print "<a href='http://";
print $row['player_website'];
print "'>Website</a></td>";
}
print "<td></td></tr>";
}
print "</table>";
?>