Jump to content

Error in query: Resource id #4??


sstoveld

Recommended Posts

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:

 

<?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:

 

asdfig.jpg

 

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 :(:confused:

Link to comment
Share on other sites

sorry for a bump so soon, dont see an option to edit my post...

 

anyway, i edited my code so the standings page on my site doesnt actually show an error in my mysql, but the links still are missing the team_id=# at the end...

 

here's the code i am currently working on:

 

<?php				
			$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>');
			}
			?>

 

edit: for some reason, my 2nd post has a modify option, but not the first

Link to comment
Share on other sites

You have no column called "team_id" in your standings table, instead you have the team name. You should have the team_id in there instead of the name however. The way you are trying to pull this information is correct, unfortunately your database is not setup that way. You can either modify your table and start inserting the team_id instead of the team name, or you will have to do a separate query to pull the team_id using the team name (I would suggest modifying your database tables to be correct). But here is how you can get the team_id. Given that you have a table called team, the team name column is also called team and the id field is called id.

 

SELECT games_played, wins, losses, ties, points, (SELECT t.id FROM team t WHERE t.team = st.team) AS team_id FROM stats st ORDER BY team_id

 

That is an example query, unsure if it will work but yea. Hopefully it helps you out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.