Jump to content

Not displaying first result


cmb

Recommended Posts

i have it set up so the user picks the year and session and then the database shows all the games in that specific year and session and then displays them with a link to their photo galleria and also shows the record(wins - losses - ties) but the way i have it know its not displaying the first result here is the code

<?php
//declares $y as year played and $s as session
$y = ' ';
$s = ' '; 

//handles submition of form for picking year and session
if (isset($_POST['submit'])) {
 $data = mysql_real_escape_string($_POST['session']);
 $exploeded = explode(",", $data);
 $y = $exploeded[0];
 $s = $exploeded[1];
}

  //Query for the selection menu
    $squery = "SELECT DISTINCT(Year_Played), Sessions FROM pinkpanther_games";
    $sresults = mysql_query($squery) or die("squery failed ($squery) - " . mysql_error());
   
    //checks $y and $s to see if their is a vaule
    if ($y == ' '){$y = '20112012';}
    if ($s == ' '){$s = '2';}
   
    //Query for getting record and for getting all the appropriate info for displaying the games
    $query = " SELECT (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Tie' ) AS 'Tie', 
         (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Win') AS 'Win',
         (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Loss') AS 'Lose',
         Opponent AS Opponent, Score AS Score, Gallery_no AS Gal, Win_Loss AS Record FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s";
    $results = mysql_query($query)  or die("Query failed ($query) - " . mysql_error());
    $row_a = mysql_fetch_assoc($results);   
    //Set record variables
    $wins = $row_a['Win'];
    $loss = $row_a['Lose'];
    $tie = $row_a['Tie'];

    //creates from and selection menu for year and session
echo "<tr><td colspan='2'><form method='post' action=''><select name='session' class='txtbox2'>";
while ($srow = mysql_fetch_assoc($sresults)){
	echo "<option value='" . $srow['Year_Played'] . "," . $srow['Sessions'] . "'>" . $srow['Year_Played'] . " Session " . $srow['Sessions'] . "</option>";	
}
echo "</select><input type='submit' name='submit' value='Go'  class='txtbox2' /></form></td></tr>";
//displays  record
echo "<tr><td colspan='2'>" .$wins . " - " . $loss . " - " . $tie . "</td></tr>";
echo "<tr></tr>";
//displays games and scores in appropriate year and session
while ($row = mysql_fetch_assoc($results)){
	$opp = $row['Opponent'];
	$score = $row['Score'];
	$gal = $row['Gal'];
	$wlt = $row['Record'];
	//styles games acording to if win lose or tie
	if ($wlt == 'Win'){
		echo "<tr><td class='win'>";
		echo "<a  href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>";
		echo "</td><td class='win'>";
		echo   $score . "";
		echo "</td></tr>";
	}
	if ($wlt == 'Loss'){	
		echo "<tr><td class='loss'>";
		echo "<a  href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>";
		echo "</td><td class='loss'>";
		echo   $score . "";
		echo "</td></tr>";
	}
	if ($wlt == 'Tie'){
		echo "<tr><td class='tie'>";
		echo "<a  href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>";
		echo "</td><td class='tie'>";
		echo   $score . "";
		echo "</td></tr>";
	}
}
?>

Link to comment
Share on other sites

added this

<?php
mysql_data_seek($results,0);
?>

befor this

<?php
while ($row = mysql_fetch_assoc($results)){
	$opp = $row['Opponent'];
	$score = $row['Score'];
	$gal = $row['Gal'];
	$wlt = $row['Record'];
	//styles games acording to if win lose or tie
	if ($wlt == 'Win'){
		echo "<tr><td class='win'>";
		echo "<a  href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>";
		echo "</td><td class='win'>";
		echo   $score . "";
		echo "</td></tr>";
	}
	if ($wlt == 'Loss'){	
		echo "<tr><td class='loss'>";
		echo "<a  href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>";
		echo "</td><td class='loss'>";
		echo   $score . "";
		echo "</td></tr>";
	}
	if ($wlt == 'Tie'){
		echo "<tr><td class='tie'>";
		echo "<a  href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>";
		echo "</td><td class='tie'>";
		echo   $score . "";
		echo "</td></tr>";
	}
}		

   ?>

and it all works now

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.