Jump to content

Archived

This topic is now archived and is closed to further replies.

phpbeginner

PHP MySQL Query help

Recommended Posts

Hello, first of all this is a great site and I have been frequenting it alot lately as I have been struggling through with MySQL and PHP a bit as a beginner and I find this place very helpful.

 

I have bascially built a database with a few tables and seem to be having some trouble with one in particular. Its for a hockey team and what I have in this table is a hockey game details. I show a few fields from the table in which they can link to the complete game details for that particular game. I have tried to do this and either get all the game detail results or none. I currently have none with the code below. I have tried linking to the complete details page by either using the gamenumber ( autoincrement primary key ) and have also tried game "date". Here is the code below and please do not laugh to loud as I am a beginner.

 

This is my game details page in which I have either gotten all records or none.....

 

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]mysql_connect($dbserver, $dbuser, $dbpass)

or die ("UNABLE TO CONNECT TO DATABASE");

mysql_select_db($dbname)

or die ("UNABLE TO SELECT DATABASE");

echo "<table width=500 bgcolor=000000 cellpadding=2 border=1><tr><td width=200 height=20 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><b>Teams</b></u></td><td width=50 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><b>1st </b></u></td><td width=50 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><b>2 nd</b></u></td><td width=50 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><b>3 rd</b></u></td><td width=50 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><b>Total</b></div></u></td><td width=50 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><b>SOG</b></u></td>";

echo "</td></tr></table>";

 

$sql = 'SELECT gamenumber, versus, sea_score_1st, sea_score_2nd, sea_score_3rd, sea_score_total, vs_score_1st, vs_score_2nd, vs_score_3rd, vs_score_total, sea_shots, vs_shots, period1_scores, period2_scores, period3_scores, period1_penalties, period2_penalties, period3_penalties FROM `game` WHERE gamenumber ="$gamenumber"';;

$result = mysql_query($sql);

if ($myrow = mysql_fetch_array($result)) {

do

{

 

$date=$myrow["date"];

$gamenumber=$myrow["gamenumber"];

$versus=$myrow["versus"];

$sea_score_1st=$myrow["sea_score_1st"];

$sea_score_2nd=$myrow["sea_score_2nd"];

$sea_score_3rd=$myrow["sea_score_3rd"];

$sea_score_total=$myrow["sea_score_total"];

$vs_score_1st=$myrow["vs_score_1st"];

$vs_score_2nd=$myrow["vs_score_2nd"];

$vs_score_3rd=$myrow["vs_score_3rd"];

$vs_score_total=$myrow["vs_score_total"];

$sea_shots=$myrow["sea_shots"];

$vs_shots=$myrow["vs_shots"];

$period1_scores=$myrow["period1_scores"];

$period2_scores=$myrow["period2_scores"];

$period3_scores=$myrow["period3_scores"];

$period1_penalties=$myrow["period1_penalties"];

$period2_penalties=$myrow["period2_penalties"];

$period3_penalties=$myrow["period3_penalties"];

echo "<table width=500 bgcolor=#232323 cellpadding=2 border=1><tr><td width=200 height=20 bgcolor=#333333 valign=top>";

echo "<font face=Tahoma size=2 color=ffffff><b>Seahawks</b></font><hr>";

echo "<font face=Tahoma size=2 color=ffffff><b>$versus</b></font></td>";

echo "<td width=50 height=20 bgcolor=#333333>";

echo "<font face=Tahoma size=2 color=ffffff>$sea_score_1st<hr>";

echo "<font face=Tahoma size=2 color=ffffff>$vs_score_1st</td>";

echo "<td width=50 height=20 bgcolor=#333333>";

echo "<font face=Tahoma size=2 color=ffffff>$sea_score_2nd<hr>";

echo "<font face=Tahoma size=2 color=ffffff>$vs_score_2nd</td>";

echo "<td width=50 height=20 bgcolor=#333333>";

echo "<font face=Tahoma size=2 color=ffffff>$sea_score_3rd<hr>";

echo "<font face=Tahoma size=2 color=ffffff>$vs_score_3rd</td>";

echo "<td width=50 height=20 bgcolor=#333333>";

echo "<font face=Tahoma size=2 color=ffffff>$sea_score_total<hr>";

echo "<font face=Tahoma size=2 color=ffffff>$vs_score_total</td>";

echo "<td width=50 height=20 bgcolor=#333333>";

echo "<font face=Tahoma size=2 color=ffffff>$sea_shots<hr>";

echo "<font face=Tahoma size=2 color=ffffff>$vs_shots</td>";

echo "</td></tr></table>";

echo "<table width=750 bgcolor=#232323 cellpadding=2 border=1>";

echo "<tr><td bgcolor=000000><font face=Tahoma size=2 color=ff0000><b><center><u>1st Period Scoring</u></center></b></font></td></tr><br>";

echo "<tr><td bgcolor=333333><font face=Tahoma size=2 color=ffffff>$period1_scores</font></td></tr>";

echo "<tr><td bgcolor=000000><font face=Tahoma size=2 color=ff0000><b><center><u>2nd Period Scoring</u></center></b></font>";

echo "<tr><td bgcolor=333333><font face=Tahoma size=2 color=ffffff>$period2_scores</font>";

echo "<tr><td bgcolor=000000><font face=Tahoma size=2 color=ff0000><b><center><u>3rdPeriod Scoring</u></center></b></font>";

echo "<tr><td bgcolor=333333><font face=Tahoma size=2 color=ffffff>$period3_scores</font>";

echo "<tr><td bgcolor=000000><font face=Tahoma size=2 color=ff0000><b><center><u>1st Period Penalties</u></center></b></font>";

echo "<tr><td bgcolor=333333><font face=Tahoma size=2 color=ffffff>$period1_penalties</font>";

echo "<tr><td bgcolor=000000><font face=Tahoma size=2 color=ff0000><b><center><u>2nd Period Penalties</u></center></b></font>";

echo "<tr><td bgcolor=333333><font face=Tahoma size=2 color=ffffff>$period2_penalties</font>";

echo "<tr><td bgcolor=000000><font face=Tahoma size=2 color=ff0000><b><center><u>3rd Period Penalties</u></center></b></font>";

echo "<tr><td bgcolor=333333><font face=Tahoma size=2 color=ffffff>$period3_penalties</font>";

echo "</td></tr></table><p>";

}

while ($myrow = mysql_fetch_array($result));

}

?>

 

Here is the basic one with the link in which I am trying to get to the specific record of the game....

 

 

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]mysql_connect($dbserver, $dbuser, $dbpass)

or die ("UNABLE TO CONNECT TO DATABASE");

mysql_select_db($dbname)

or die ("UNABLE TO SELECT DATABASE");

 

echo "<table width=500 bgcolor=000000 cellpadding=2 border=1><tr><td width=100 height=20 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><div align=center><b>DATE</b></div></u></td><td width=300 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><div align=center><b>GAME SCORE</b></div></u></td><td width=100 bgcolor=#000000><font face=Tahoma size=2 color=#ff0000><u><div align=center><b>DETAILS</b></div></u>";

echo "</td></tr></table>";

 

$sql = 'SELECT DISTINCT `date`,`versus`,`sea_score_total`,`vs_score_total`, `gamenumber` FROM `game` ';;

$result = mysql_query($sql);

if ($myrow = mysql_fetch_array($result)) {

do

{

$date=$myrow["date"];

$versus=$myrow["versus"];

$sea_score_total=$myrow["sea_score_total"];

$vs_score_total=$myrow["vs_score_total"];

$gamenumber=$myrow["gamenumber"];

echo "<table width=500 bgcolor=#232323 cellpadding=2 border=1><tr><td width=100 height=20 bgcolor=#333333 valign=top>";

echo "<font face=Tahoma size=2 align=center>$date</a></font></td>";

echo "<td height=20 bgcolor=#333333 valign=top>";

echo "<font face=Tahoma size=2> <b><font color=ff00000>Seahawks</b></font> - $sea_score_total";

echo "  <font color=ff0000><b>$versus</b></font> - $vs_score_total</td>";

echo "<td bgcolor=333333><font color=FF0000><b><a href=viewgame.php?gamenumber=$gamenumber> Details </a></b></font>";

echo "</td></tr></table>";

 

}

while ($myrow = mysql_fetch_array($result));

}

?>

 

I did get this far and everything so far has been working good for me. Thanks in advance.

 

Share this post


Link to post
Share on other sites

on the first one, replace the single quotes with double and vice versa. a variable inside a single-quoted string is not parsed to its value.

Share this post


Link to post
Share on other sites

×

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.