Error in query: Resource id #4??
Posted on
16th Feb 2014 07:03 pm by
admin
hey guys, having a minor (i think) problem here that i havent been able to figure out. long story short, im building a hockey stat tracking site for a local hockey league around here.
my problem is, i am trying to run a query using php, but the value getting returned is Resource id #4 instead of what it is supposed to be. i read around and found people saying you need to use mysql_fetch_array, which is what i am doing. let me start by posting my code:
Code: <?php
$querystats = mysql_query('SELECT * FROM stats ORDER BY team_id');
$statsresult = mysql_query($querystats);
if (!$statsresult) {
exit ('<p>Error in query.'. mysql_error().'</p>');
}
while($row = mysql_fetch_array($statsresult)) {
echo $row['team_id'];
print_r($team_id);
$querystandings = mysql_query('SELECT * FROM standings ORDER BY points DESC');
if (!$querystandings) {
exit ('<p>Error in query.'. mysql_error().'</p>');
}
while ($row = mysql_fetch_array($querystandings)) {
echo('<tr><td>' . '<a href="teams.php?team_id='.$row['team_id'].'"> ' . $row['team'] . '</a></td><td>' . $row['games_played'] . '</td><td>' . $row['wins'] . '</td><td>' . $row['losses'] . '</td><td>' . $row['ties'] . '</td><td>' . $row['points'] . '</td></tr>');
}
}
?>
i believe the problem is the $querystats. here's what my table structure looks like:
here's a link to my site:
http://gamera.caset.buffalo.edu/~sstoveld/DMS315/projects/final/standings.php
you can login with: username: test password: test
the problem is on the standings page, if you hover over a team name and look at where the link directs to, it ends with team_id=
i need to get the proper team_id in the link, which is where im hoping someone can help me. ive been looking through this trying many different things that i cant seem to get to work.
if my above code is completely wrong with using the $querystats query, how can i get this to work.
originally the $querystats query wasnt there, and only the $querystandings query was being used, but the links wouldnt work because i am not selecting the team_id from the stats table. when i modify the $querystandings query to left join on stats, the loop goes through and adds about 25 entries per team, which is not what i want.
if you need any more info, please ask, i cant figure this out
No comments posted yet
Your Answer:
Login to answer
216
41
Other forums
update sql when refresh - php
hi
I have made a table (attachement)
the users can update the sql database using + or x bu
Had a simple form script that suddenly stopped working
It was made about a year ago and had been working fine. Last time it was known to work for sure was
Xml parsing
I need a suggestion about parsing xml with multiply parts like pervious...
i.e. different device
VAT
how should I deal with VAT?
if I have a product that costs £5.00 and VAT @ 17.5% (£0.87
Empty text file when there is over XXXX lines of text.
define("RANDOM_FILE","/public_html/random.txt");
$randomEntry = "
update the selected existing records of database
Hi frndz,
I am new to php and get stuck....
Edit.php > Update.php > Updatea
Display certain image depending on time of year
Hi, I am new to these forums and would really appreciate some advice on a piece of coding I have don
Error querying database.
I get the above error when trying to insert some values to a datatable.
Here's the code :
problem with refreshing
in my site, i have an index page, it has a main div. this main div's content is changing according t
help with mysql_error()
Hi,
I am trying to insert data into a table, but I am not able to insert it. I wanted to see