Log in

View Full Version : Select From Statement



captainjustin
01-08-2011, 08:13 AM
Working on a photo album that displays pictures by the month and year. The month and year is passed tru the url to the album. I'm not sure what I'm doing wrong here but I'm not getting any results... Any Help would be appreciated......





<?
$pmonth= $_GET["pmonth"];
$pyear= $_GET["pyear"];


$submit=fn;
$order_type=fn;
if (!$ByPage) $ByPage=8;
if (!$Start) $Start=0;
// Set how wide you want your table
$tblWidth = 4;
////////// I think this is where my problem is
$sql = mysql_query("select * from photo_album where pmonth = \"$pday\" and pyear = \"$pyear\" limit $Start,$ByPage");
$i = 1;
echo '<table align=center>';
// Check to see if any results were returned
if(mysql_num_rows($sql) > 0){
echo '<tr>';
// Loop through the results
while($row = mysql_fetch_array($sql)){
echo '<td><a rel="example_group" href="images/'. $row['fn'] .'" title="'. $row['title'] .' <br> Date: '. $row['date'] .' <br>'. $row['disc'] .'"><img src="images/'. $row['fn'] .'" width="120" height="100" /></a><br><br><center><a href="javascript:ajaxpagefetcher.load(\'demo\', \'see_comments.php?fn='. $row['fn'] .'\', false)">'. $row['rp'] .'<img src="icons/comments.png" width="16" height="16" title="See Comments" border="0"/></a>&nbsp;&nbsp;&nbsp;<a href="post_comment.php?fn='. $row['fn'] .'" onclick="PostComment(this.href,\'name\',\'475\',\'300\',\'No\');return false"><img src="icons/post.png" width="16" height="16" title="Post Comment" border="0"/></a>
</td>';
if($i == $tblWidth){
echo '</tr><tr>';
$i = 0;
}
$i++;
}
echo '</tr>';
}else{
echo '<tr><td>No Pictures Posted Yet!<br><br><a class=TNA href="admin/admin_album.php">Click Here</a> to upload pictures.</td></tr>';
}
echo '</table>';
$cp = "select count(fn) from photo_album";
$rcp = mysql_query($cp) or die (mysql_error());
$ap = mysql_fetch_array($rcp);
$a = $ap[0];

echo "<table width=500 align=center cellspacing=0><tr>";

if ($a <= $ByPage && $Start == '0')
{

}

elseif ($a > $Start + $ByPage && $Start + $ByPage >= $a || $Start == 0 )
{
$nom = $Start + $ByPage;
echo "<td align=right><a class=TNA href=\"album.php?submit=$submit&order_type=$order_type&Start=$nom\">Next Page <img src=\"icons/next.gif\" width=\"16\" height=\"16\" alt=\"Next Page\" border=\"0\"/></a></td>";
}
elseif ( ($Start < $a && $Start > $ByPage) || ($Start + $ByPage >= $a))
{
$nom1 = $Start - $ByPage;
echo "<td align=left><a class=TNA href=\"album.php?submit=$submit&order_type=$order_type&Start=$nom1\"><img src=\"icons/back.gif\" width=\"16\" height=\"16\" alt=\"Next Page\" border=\"0\"/> Back</a></td>";
}
else
{
$nom1 = $Start - $ByPage;
echo "<td align=left><a class=TNA href=\"album.php?submit=$submit&order_type=$order_type&Start=$nom1\">previous</a></td>";
$nom = $Start + $ByPage;
echo "<td align=right><a class=TNA href=\"album.php?submit=$submit&order_type=$order_type&Start=$nom\">next</a></td>";
}

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

exit;



?>

Schmoopy
01-08-2011, 11:55 AM
Looks like you're just using the wrong variable name:



$sql = mysql_query("select * from photo_album where pmonth = \"$pday\" and pyear = \"$pyear\" limit $Start,$ByPage");


You're using $pday, instead of $pmonth. Try changing that and see what happens.



$sql = mysql_query("select * from photo_album where pmonth = \"$pmonth\" and pyear = \"$pyear\" limit $Start,$ByPage");

captainjustin
01-09-2011, 09:50 PM
That was it..... I knew it hat to be some silly mistake.... Need to stop trying to write code at 2am..... Thanks