Jump to content

Need help?


darkfreaks

Recommended Posts

okay so i got a page thing coded but now it counts every single wallpaper instead of 30 then echoing how many pages there are.

 

 

<?php

if (isset($_GET['page'])) { $page  = $_GET['page']; } else { $page=1; };
$start_from = ($page-1) * 20;
$sql = "SELECT * FROM Wallpaper ORDER BY ID DESC LIMIT $start_from, 20";
$rs_result = mysql_query ($sql);

$sql = "SELECT COUNT(Category) FROM Wallpaper";

$rs_result = mysql_query ($sql);
$total_pages = ceil($total_records / 30);
$total_records = $row[0];

for ($i=1; $i<=$total_pages; $i++) {
            echo "<a href=categories.php?page=.$i.>$i</a>";
};
?>

Link to comment
https://forums.phpfreaks.com/topic/82896-need-help/
Share on other sites

It's hard to really see what's wrong without the entire code. Do you see how you are overwriting the value of both your $sql and $rs_result variable. Same as:

 

$x = 1;

$x = 5;

 

The first select statement means nothing, and neither does it's result, or at least that is what I get from the supplied code.

Link to comment
https://forums.phpfreaks.com/topic/82896-need-help/#findComment-421595
Share on other sites

<?php

$Category = $_GET['Category'];
$SEO_Title = "$Category wallpapers";
$SEO_Description = "Download the best $Category 
wallpapers FREE. We provide 800x600 and 1280x1024 sized images.";
$SEO_Keywords = "wallpaper, wallpapers, naruto, free, ".$Category;
$SEO_H1 = "Free $Category wallpapers.";

$image_path ="../..";
include_once("skin.php");
echo $header;
echo "<h2>$Category wallpapers</h2>";

if ($image_path == "")
{
$image_path=$_SERVER['REQUEST_URI'];
}

if (substr($image_path,strlen($image_path)-1,1) != "/")
$image_path=$image_path."/";

//Category wallpapers.
#get the category ID
$cCategory = str_replace("+", " ", $Category);
$cQuery = "SELECT * FROM `Categories` WHERE `name`='$cCategory' LIMIT 1";
$cResult = mysql_query($cQuery) or die(mysql_error());
if (mysql_num_rows($cResult) <= 0)
{
echo "There are currently no wallpapers in this category.";
} else
{
$Row = mysql_fetch_object($cResult);
$id = $Row->id;

$result = mysql_query("SELECT * FROM `Wallpapers` 
WHERE `Category` = '".$id."' OR `Category` IN (SELECT `id` 
FROM `Categories` WHERE `Parent` = '".$id."') AND `approved` = '0' ORDER BY
`ID` DESC LIMIT");
$x = 0;	
if (mysql_num_rows($result) <= 0)
{
	echo "There are currently no wallpapers in this category.";
} else
{
	while ($row = mysql_fetch_assoc($result)) {
		$x += 1;
		echo "\n".'<div class="Box Left">'."\n\t";
			echo '<div style="font-size: 1em; margin-bottom: 5px;"><a href="'.$image_path.'wallpaper/'.str_replace(" ", "-", $row['Title']).'/">'.$row['Title']."</a></div>";
			echo '<a href="'.$image_path.'wallpaper/'.str_replace(" ", "-", $row['Title']).'/"><img class="Thumbnail" src="'.$image_path.'images/wallpapers/'.$row['Thumbnail'].'" alt="'.$row['Name'].'" /></a>';
			echo '<div class="Clear"></div>'."\n";
		echo '</div>';
		if (!is_int($x/3)){
			echo '<div class="Spacer"> </div>';
		}
	}
}
}
echo '<div class="Clear"></div>';

if (isset($_GET['page'])) { $page  = $_GET['page']; } else { $page=1; };
$start_from = ($page-1) * 20;
$sql = "SELECT * FROM Wallpaper WHERE `Category` = '".$id."' OR `Category` IN(SELECT `id` FROM `Categories` WHERE `Parent` = '".$id."') AND `approved` = '0' ORDER BY ID DESC LIMIT $start_from, 20";
$rs_result = mysql_query ($sql);

$sql = "SELECT COUNT(Category) FROM Wallpaper";

$total_pages = ceil($total_records / 30);
$total_records = $row[0];
$row = mysql_fetch_array($rs_result);


for ($i=1; $i<=$total_pages; $i++) {
            echo "<a href=categories.php?page=.$i.>$i</a>";
};



echo $footer;


?>

Link to comment
https://forums.phpfreaks.com/topic/82896-need-help/#findComment-421596
Share on other sites

If all this is for is pagination, then I think the following code may be getting closer to what you want:

 

if (isset($_GET['page'])) { $page  = $_GET['page']; } else { $page=1; };
$start_from = ($page-1) * 20;
$sql = "SELECT * FROM Wallpaper WHERE `Category` = '".$id."' OR `Category` IN(SELECT `id` FROM `Categories` WHERE `Parent` = '".$id."') AND `approved` = '0' ORDER BY ID DESC LIMIT $start_from, 20";
$rs_result = mysql_query ($sql);
$total_records = mysql_num_rows($rs_result);
$total_pages = ceil($total_records / 30);
for ($i=1; $i<=$total_pages; $i++) {
            echo "<a href='categories.php?page='.$i.'>'.$i.'</a>";
};

Link to comment
https://forums.phpfreaks.com/topic/82896-need-help/#findComment-421619
Share on other sites

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/.vermin/epicso/wallpaper-vault.com/categories.php on line 36

There are currently no wallpapers in this category.

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/.vermin/epicso/wallpaper-vault.com/categories.php on line 60

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/82896-need-help/#findComment-421629
Share on other sites

Your queries have odd single quote characters in them. The names of your table and database fields should not be in single quotes.

 

$result = mysql_query("SELECT * FROM `Wallpapers`

WHERE `Category` = '".$id."' OR `Category` IN (SELECT `id`

FROM `Categories` WHERE `Parent` = '".$id."') AND `approved` = '0' ORDER BY

`ID` DESC LIMIT");

 

You ought to try to test your queries in phpMyAdmin or the MySQL console to make sure they are good before sticking them in your php.

Link to comment
https://forums.phpfreaks.com/topic/82896-need-help/#findComment-421639
Share on other sites

Archived

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

×
×
  • 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.