Originally posted by drew010
the reason it shows Resource ID #4 is because you are trying to echo a value that is a resource, in this case a mysql connection id.
the problem comes from
$numPhotos=mysql_query($sql1);
and
$end=min($whichPage*12,$numPhotos);
you issued the query but you still have to retrive the results with mysql_fetch_row or mysql_fetch_array.
try
$numPhotos=mysql_query($sql1);
$photoCount = mysql_fetch_row($numPhotos);
$photoCount = $photoCount[0];
then
$end=min($whichPage*12,$photoCount);
Done...however I still get the error regarding line #31, and the bottom looks like this:
Resource id #4 total | Displaying 1-121 |
Here's the code as it stands now:
<?
ini_set("display_errors", 1);
error_reporting(E_ALL);
$linktext2 ="";
$dbname = "[dbname]";
$connection = @mysql_connect("localhost", "[username]", "[password]") or die("Couldn't Connect.");
$db = @mysql_select_db($dbname, $connection) or die("Couldn't Select Database.");
$sql = "SELECT * FROM mlb WHERE team = '$team' ORDER BY year,gid DESC";
function makePageLink($pageNum,$linkTitle="") {
$pageName="test.php";
$link= "<a href=\"".$pageName;
$link.= "?page=\"" .$pageNum. ">";
if ($linkTitle != "") {
$link .= $linkTitle;
} else {
$link .= $pageNum;
}
$link.= "</a>";
return $link;
}
$whichPage=$_GET["page"];
if (!isset($GET['page'])) {
$whichPage = 1;
} else {
$whichPage = $GET['page'];
}
//gets number of rows/photos
$sql1="SELECT COUNT(*) FROM mlb WHERE team = '$team'";
$result1 = @($sql1,$connection) or die("Couldn't Execute Query for # 1");
$numPhotos=mysql_query($sql1);
$photoCount = mysql_fetch_row($numPhotos);
$photoCount = $photoCount[0];
//number of pages of 12 photos each
$numPages= ceil($numPhotos / 12);
//determines where to start and end count
$start=($whichPage-1)12+1;
$end=min($whichPage12,$photoCount);
//get 12 entries that will be displayed
$sql2 = "SELECT * FROM mlb WHERE team = '$team' ORDER BY year,gid DESC LIMIT $start,12";
$result = @($sql2,$connection) or die("Couldn't Execute Query for # 1");
$i = 1;
$cols = 3;
$dollar = "$";
echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=602><tr><td colspan=$cols HEIGHT=10><IMG SRC=\"/images/dot.gif\"></td></tr><tr VALIGN=TOP>";
while ($row=@mysql_fetch_array($result)) {
if ($i > $cols) {
echo "</tr><tr><td colspan=$cols HEIGHT=10><IMG SRC=\"/images/dot.gif\"></td></tr><tr VALIGN=TOP>";
echo "<td WIDTH=190><table border=\"1\" width=\"100%\" bordercolor=\"#DCDCDC\" cellspacing=\"0\" cellpadding=\"5\"><tr><td><p align=\"center\"><IMG SRC=\"/images/mlb/" . $row["team"] . "/" . $row["year"] . "" . $row["photo"] . "sm.jpg\" alt=\"$team Pictures: " . $row["player"] . " - " . $row["description"] . "\" " . $row["position"] . "><br><font size=\"1\" face=\"Arial\"><center><b>$team Photo:<br>" . $row ["name"] . "<br><font size=\"1\" face=\"Arial\"><font color=\"#800000\"><strike>Price $ " . $row ["regular"] . "</strike></font> $" . $row ["price"] . "<a href=\"/mlb/display.php?id=" . $row ["item_id"] . "$linktext2\"><br><IMG SRC=\"/images/view_item.jpg\" width=70 height=20 border=0></a></center></td></tr></table></td>";
$i = 2;
} else {
echo "<td WIDTH=190><table border=\"1\" width=\"100%\" bordercolor=\"#DCDCDC\" cellspacing=\"0\" cellpadding=\"5\"><tr><td><p align=\"center\"><IMG SRC=\"/images/mlb/" . $row["team"] . "/" . $row["year"] . "" . $row["photo"] . "sm.jpg\" alt=\"$team Pictures: " . $row["player"] . " - " . $row["description"] . "\" " . $row["position"] . "><br><font size=\"1\" face=\"Arial\"><center><b>$team Photo:<br>" . $row ["name"] . "<br><font size=\"1\" face=\"Arial\"><font color=\"#800000\"><strike>Price $ " . $row ["regular"] . "</strike></font> $" . $row ["price"] . "<br><a href=\"/mlb/display.php?id=" . $row ["item_id"] . "$linktext2\"><IMG SRC=\"/images/view_item.jpg\" width=70 height=20 border=0></a></center></td></tr></table></td>";
$i++;
}
}
echo "</table>";
echo $numPhotos. " total | Displaying " .$start. "-" .$end;
if ($whichPage != 1) {
$link=makePageLink($whichPage-1,"[previous]");
echo $link;
}
for ($iter=1; $iter<= $numPages; ++$iter) {
$link=makePageLink($iter);
echo $link." | ";
}
if ($whichPage != $numPages) {
$link=makePageLink($whichPage+1,"[next]");
echo $link;
}
?>
You guys have been a lot of help, I appreciate it.
Ian