Jump to content

Query returns no results


cmb

Recommended Posts

this is my query that returns no results

<?php
$query = "SELECT * FROM pinkpanther_games WHERE Year_Played = '$yp' AND Sessions = '$s' ORDER BY id ASC ";
?>

i checked to make shore $yp and $s were actually set, which they were, then i replaced them with actual values like this

<?php
$query = "SELECT * FROM pinkpanther_games WHERE Year_Played = '20112012' AND Sessions = '2' ORDER BY id ASC ";
?>

and it returned the correct number of records  idk what the problem is this is all the code for the page if that matters

   		<?php
$n_query = "SELECT COUNT(id) AS 'count', Year_Played, Sessions FROM pinkpanther_games GROUP BY Year_Played, Sessions ORDER BY Year_Played DESC, Sessions ASC";
$n_results = mysql_query($n_query) or die("Query failed ($n_query) - " . mysql_error());
$syp_row = mysql_fetch_array($n_results);
mysql_data_seek($n_results,0);
$years = array();
$y_s = array();
while ($n_row = mysql_fetch_array($n_results)){
	array_push($y_s,$n_row['count'],$n_row['Year_Played'],$n_row['Sessions']);
	array_push($years,$y_s);
	unset($y_s);
	$y_s = array();
}
$count = count($years);
$x = 0;
while ($x < $count){
	$s = $years[$x][1];
	$yp = $years[$x][2];
	echo $s . "||" . $yp ."<br />";
	$query = "SELECT * FROM pinkpanther_games WHERE Year_Played = '$yp' AND Sessions = '$s' ORDER BY id ASC ";
	$results = mysql_query($query) or die ("Query failed ($query) -" . mysql_error());
	$lrow = mysql_fetch_assoc($results);

	$date1 = substr($lrow['Year_Played'], 0,4);
	$date2 = substr($lrow['Year_Played'],4,;
	echo "<fieldset><legend>" . $date1 . "-" . $date2 . " Session " . $lrow['Sessions'] ."</legend>";
	mysql_data_seek($results,0);		
	while ($row = mysql_fetch_assoc($results)){
		$g = $row['Gallery_no'];
		echo "<a href='galleries.php?g=$g'>" . $row['Opponent'] . "</a><br />";			
	}
	echo "</fieldset><br />";
	$x++;	
}
?>

Link to comment
Share on other sites

your running a select * inside a while loop, that's a way bigger problem than not getting any results back. Fix your code, you should only need a single query run once. If you can't manage it yourself post up an exact breakdown of what you are trying to acomplish and someone will help you out.  Once you fix that your results problem wont even factor.

Link to comment
Share on other sites

The first part of my code groups all the records in my database by the year and then by the session and then puts it all into an array

   		<?php
$n_query = "SELECT COUNT(id) AS 'count', Year_Played, Sessions FROM pinkpanther_games GROUP BY Year_Played, Sessions ORDER BY Year_Played DESC, Sessions ASC";
$n_results = mysql_query($n_query) or die("Query failed ($n_query) - " . mysql_error());
$syp_row = mysql_fetch_array($n_results);
mysql_data_seek($n_results,0);
$years = array();
$y_s = array();
while ($n_row = mysql_fetch_array($n_results)){
	array_push($y_s,$n_row['count'],$n_row['Year_Played'],$n_row['Sessions']);
	array_push($years,$y_s);
	unset($y_s);
	$y_s = array();
}
?>

The array looks like this

Array (
    [0] => Array
        (
            [0] => 9                                 //The number of records
            [1] => 20112012                   //The year
            [2] => 1                                 //The session
        )

    [1] => Array
        (
            [0] => 1                                        
            [1] => 20112012
            [2] => 2
        )

    [2] => Array
        (
            [0] => 11
            [1] => 20102011
            [2] => 1
        )

    [3] => Array
        (
            [0] => 10
            [1] => 20102011
            [2] => 2
        )

)

then i count the number of values in the array so i can set up my while loop

and the reason that my second query is in the while loop is because now what i want to do is  show all the records for each year and session. So i just change the variables in the query

this is the rest of the code

<?php
$s = $years[$x][1];
	$yp = $years[$x][2];
	echo $s . "||" . $yp ."<br />";
	$query = "SELECT * FROM pinkpanther_games WHERE Year_Played = '$yp' AND Sessions = '$s' ORDER BY id ASC ";
	$results = mysql_query($query) or die ("Query failed ($query) -" . mysql_error());
	$lrow = mysql_fetch_assoc($results);

	$date1 = substr($lrow['Year_Played'], 0,4);
	$date2 = substr($lrow['Year_Played'],4,;
	echo "<fieldset><legend>" . $date1 . "-" . $date2 . " Session " . $lrow['Sessions'] ."</legend>";
	mysql_data_seek($results,0);		
	while ($row = mysql_fetch_assoc($results)){
		$g = $row['Gallery_no'];
		echo "<a href='galleries.php?g=$g'>" . $row['Opponent'] . "</a><br />";			
	}
	echo "</fieldset><br />";
	$x++;	
}

   ?>

So any help on a more correct way to do this would be great

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.