Problems with detailed linkpage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Problems with detailed linkpage

Post by warriors2003 »

Ok,,I have an overall Baseball Stats table. I want it so when you click on the player, it will then take you to the game by game breakdown page for that player listing all his games.

Overall Stats are located in a table "hit"
I have hit_id as auto, prim, unique

The individual game stats are in "hitg"
it has hitid, no auto, no prim, no unique, and feeds quite well from the hit_id i have from the submit form.

The form I have works, everythign goes into the two tables nicely. One adds them up "hit", the other keeps them all seperate "hitg".

Here is the problem,,,In the overall stats table i'm using this as the link in the code to take you to the hitplayer breakdown page

echo "<a href=hitplayer.php?hit_id=$row[hit_id]>";

Now the problem I';m having is making that hitplayer.php page. I've been looking around, try different codes, but can;t get one to work. I don;t know if its becuase I have soemthign screwy in the field name in the table or hit id's are conflicting.

Here is what i picked up from doing some reasearch

CODE--------------------------

<?

mysql_query("select * from hitg where hitid = '$hit_id'");

?>
<tr>
<td align=center valign=top><B>AB</B></td>
<td align=center valign=top><B>hits</B></td>
<td align=center valign=top><B>hr</B></td>
</tr>

<?
// Display requested entries
while ( $row = mysql_fetch_array($result) ) {
echo("<tr>
<td align=center valign=top>
". $row["ab"] . "</td>
<td align=center valign=top>
" . $row["h"] . "</td>
<td align=center valign=top>
" . $row["hr"] . "</td></tr>");

}

?>
____________________ End Code


I know their maybe something screwy with the id and how i have it setup in the query, or maybe its in the linkage to i dunno.

Its just a matter of querying just the ID's games in the breakdown on hitg and displaying them right from the link that is throwing me off.

THANKS SO MUCH IN ADVANCE!!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try this as your query :
mysql_query("select * from hitg where hitid = '{$_GET['hit_id']}'") or die(mysql_error());
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

THANKS FOR YOUR HELP!!! However it didn't work,,i'm starting to think something is screwy in the tables with the ID's?? or maybe the link I used?? Do I need to edit that?

I used this and no results showed up. I put in what you added.

<?

mysql_query("select * from hitg where hitid = '{$_GET['hit_id']}'") or die(mysql_error());

?>
<tr>
<td align=center valign=top><B>AB</B></td>
<td align=center valign=top><B>hits</B></td>
<td align=center valign=top><B>hr</B></td>
</tr>

<?
// Display requested entries
while ( $row = mysql_fetch_array($result) ) {
echo("<tr>
<td align=center valign=top>
". $row["ab"] . "</td>
<td align=center valign=top>
" . $row["h"] . "</td>
<td align=center valign=top>
" . $row["hr"] . "</td></tr>");

}

?>
-----------------------

Any ideas to what could be causing no output?

Thanks again for taking time out to try to help me!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, to debug, i'd do this.
$sql = "SELECT * FROM hitg WHERE hitid='{$_GET['hit_id']}'";
echo $sql; //for debugging
mysql_query($sql) or die(mysql_error());

Make sure the echo looks ok...what does it output?
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Nothing,,it's blank,,so something is messed up. Any ideas? Thanks again
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Hmm..it can't be blank unless you've put it on the wrong page or there's code you're not showing us :o
At the very least it should show "SELECT * FROM hit WHERE hitid=''"
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Do you think my link is the problem here?

echo "<a href=hitplayer.php?hit_id=$row[hit_id]>";

Also how exactly should i include the debug in the page and where do i need to put it? Sorry if its a basic question, sometimes i can do real advance things then simple stuff i got lost on 8O


here is the overall table then you can click on a player
http://www.becauseitscool.com/htables22.php
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Nope, that looks fine.
Can you post exactly what you have in hitplayer.php ?
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Thanks so much for trying to helP!!!

This is what i have, i added in what you gave me

Code--------------------------------
<?

mysql_query("select * from hitg where hitid = '{$_GET['hit_id']}'") or die(mysql_error());

?>
<tr>
<td align=center valign=top><B>AB</B></td>
<td align=center valign=top><B>hits</B></td>
<td align=center valign=top><B>hr</B></td>
</tr>

<?
// Display requested entries
while ( $row = mysql_fetch_array($result) ) {
echo("<tr>
<td align=center valign=top>
". $row["ab"] . "</td>
<td align=center valign=top>
" . $row["h"] . "</td>
<td align=center valign=top>
" . $row["hr"] . "</td></tr>");

}

?>
End Code-------------------------
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, to debug, i'd do this.
$sql = "SELECT * FROM hitg WHERE hitid='{$_GET['hit_id']}'";
echo $sql; //for debugging
mysql_query($sql) or die(mysql_error());

Make sure the echo looks ok...what does it output?
Try that and tell us what the echo outputs.
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Where abouts do i put this in the page? Sorry if i sound dumb :(
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Replace ...

mysql_query("select * from hitg where hitid = '{$_GET['hit_id']}'") or die(mysql_error());

with ...

$sql = "SELECT * FROM hitg WHERE hitid='{$_GET['hit_id']}'";
echo $sql; //for debugging
mysql_query($sql) or die(mysql_error());
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

Ok ya, that's what i was thinking,,i got this

SELECT * FROM hitg WHERE hitid='22' AB hits hr
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Ack..i missed the most obvious error right from the start, sorry.
You have:
mysql_query("select * from hitg where hitid = '{$_GET['hit_id']}'") or die(mysql_error());

that needs to be:
$result = mysql_query("select * from hitg where hitid = '{$_GET['hit_id']}'") or die(mysql_error());

otherwise the result returned is lost, ie not assigned to anything for the mysql_fetch_array() to work :o
warriors2003
Forum Commoner
Posts: 38
Joined: Wed Mar 24, 2004 7:24 pm

Post by warriors2003 »

THAT WAS IT!!!,,Thank you SO MUCH BRO!!! YOU ROCK!!!!

I have the results right next to each other and it doesn;t look all great visually. But now i can layout a table like I normally do right? :D
Post Reply