Само от една категория

redsystem

Registered
Как да направя този код да изкарва само темите от една категория + странициране.

Код:
echo "<table class='maintable'>"; 
$sql=mysql_query("SELECT * FROM cats ORDER by id") or die (mysql_error()); 
while($r=mysql_fetch_array($sql)) { 
$cat = $r['cat'];
$id = $r['id'];

echo "<tr class='headline'><td width='80%'><b><font color='white'>-$cat</font></b></td><td width='20%'><b><font color='white'>Автор</font></b></td></tr>";

$sqll = mysql_query("SELECT * FROM $mysql_table WHERE cat='$cat' ORDER by postid DESC ");
while ($s=mysql_fetch_array($sqll)) {
$author=$s['author'];
$title=$s['title'];
$id=$s['postid'];

echo "<tr>";
echo "<td width='80%'>";
echo "-<b><a href='index.php?pp=message&id=$id'><font color='green'>$title</font></a></b>";
echo "        $lock_unlock";
echo "</td>";
echo "<td width='20%'><b><font color='green'>$author</font></b></td>";
echo "</tr>";
}
}
print "</table>";
 
Добавил съм една променлива на име $cat в нея слагай името на категорията от която искаш да излизат ..

<?
$broinastranica = 30;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$redove = ($pageNum - 1) * $broinastranica;

$query = "SELECT COUNT(id) AS numrows FROM `cats`";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];


$maxPage = ceil($numrows/$broinastranica);

$self = $_SERVER['PHP_SELF'];
$nomeranastranici = '';

for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nomeranastranici .= " $page ";
}
else
{
$nomeranastranici .= " <a href=\"$self?page=$page\">$page</a> ";
}
}

if ($pageNum > 1)
{
$page = $pageNum - 1;
$predishna = " <font color=orange><a href=\"$self?page=$page\"> [<] </a></font> ";

$parva = " <font color=orange><a href=\"$self?page=1\">[първа]</a></font> ";
}
else
{
$predishna = ' ';
$parva = ' ';
}

if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$sledvashta = " <font color=orange><a href=\"$self?page=$page\"> [>] </a></font> ";

$posledna = " <font color=orange><a href=\"$self?page=$maxPage\">[последна]</a></font> ";
}
else
{
$sledvashta = ' ';
$posledna = ' ';
}


$cat = "kategoriqtati";
echo "<table class='maintable'>";
$sql=mysql_query("SELECT * FROM `cats` WHRE `cats` = '$cat' ORDER by id") or die (mysql_error());
while($r=mysql_fetch_array($sql)) {
$cat = $r['cat'];
$id = $r['id'];

echo "<tr class='headline'><td width='80%'><b><font color='white'>-$cat</font></b></td><td width='20%'><b><font color='white'>Автор</font></b></td></tr>";

$sqll = mysql_query("SELECT * FROM $mysql_table WHERE cat='$cat' ORDER by postid DESC ");
while ($s=mysql_fetch_array($sqll)) {
$author=$s['author'];
$title=$s['title'];
$id=$s['postid'];

echo "<tr>";
echo "<td width='80%'>";
echo "-<b><a href='index.php?pp=message&id=$id'><font color='green'>$title</font></a></b>";
echo "        $lock_unlock";
echo "</td>";
echo "<td width='20%'><b><font color='green'>$author</font></b></td>";
echo "</tr>";
}
}
print "</table>";
echo "Страница: ";
echo $nomeranastranici;
?>
 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cat = 'Новини' ORDER by id' at line 1
 
Така ? и да кажа замести conn.php с името на конфиг файла ти

<?
include "conn.php";
$broinastranica = 30;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$redove = ($pageNum - 1) * $broinastranica;

$query = "SELECT COUNT(id) AS numrows FROM `cats`";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];


$maxPage = ceil($numrows/$broinastranica);

$self = $_SERVER['PHP_SELF'];
$nomeranastranici = '';

for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nomeranastranici .= " $page ";
}
else
{
$nomeranastranici .= " <a href=\"$self?page=$page\">$page</a> ";
}
}

if ($pageNum > 1)
{
$page = $pageNum - 1;
$predishna = " <font color=orange><a href=\"$self?page=$page\"> [<] </a></font> ";

$parva = " <font color=orange><a href=\"$self?page=1\">[първа]</a></font> ";
}
else
{
$predishna = ' ';
$parva = ' ';
}

if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$sledvashta = " <font color=orange><a href=\"$self?page=$page\"> [>] </a></font> ";

$posledna = " <font color=orange><a href=\"$self?page=$maxPage\">[последна]</a></font> ";
}
else
{
$sledvashta = ' ';
$posledna = ' ';
}


$cat = "kategoriq";
echo "<table class='maintable'>";
$sql=mysql_query("SELECT * FROM `cats` WHRE `cats` = '$cat' ORDER by `id`") or die (mysql_error());
while($r=mysql_fetch_array($sql)) {
$cat = $r['cat'];
$id = $r['id'];

echo "<tr class='headline'><td width='80%'><b><font color='white'>-$cat</font></b></td><td width='20%'><b><font color='white'>Автор</font></b></td></tr>";

$sqll = mysql_query("SELECT * FROM '$mysql_table' WHERE cat='$cat' ORDER by `postid` DESC ") or die (mysql_error());
while ($s=mysql_fetch_array($sqll)) {
$author=$s['author'];
$title=$s['title'];
$id=$s['postid'];

echo "<tr>";
echo "<td width='80%'>";
echo "-<b><a href='index.php?pp=message&id=$id'><font color='green'>$title</font></a></b>";
echo "        $lock_unlock";
echo "</td>";
echo "<td width='20%'><b><font color='green'>$author</font></b></td>";
echo "</tr>";
}
}
print "</table>";
echo "Страница: ";
echo $nomeranastranici;
?>
 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`cats` = 'Новини' ORDER by `id`' at line 1


Отново :|
 
<?
include "conn.php";
$broinastranica = 30;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$redove = ($pageNum - 1) * $broinastranica;

$query = "SELECT COUNT(id) AS numrows FROM `cats`";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];


$maxPage = ceil($numrows/$broinastranica);

$self = $_SERVER['PHP_SELF'];
$nomeranastranici = '';

for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nomeranastranici .= " $page ";
}
else
{
$nomeranastranici .= " <a href=\"$self?page=$page\">$page</a> ";
}
}

if ($pageNum > 1)
{
$page = $pageNum - 1;
$predishna = " <font color=orange><a href=\"$self?page=$page\"> [<] </a></font> ";

$parva = " <font color=orange><a href=\"$self?page=1\">[първа]</a></font> ";
}
else
{
$predishna = ' ';
$parva = ' ';
}

if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$sledvashta = " <font color=orange><a href=\"$self?page=$page\"> [>] </a></font> ";

$posledna = " <font color=orange><a href=\"$self?page=$maxPage\">[последна]</a></font> ";
}
else
{
$sledvashta = ' ';
$posledna = ' ';
}


$cat = "kategoriq";
echo "<table class='maintable'>";
$sql=mysql_query("SELECT * FROM `cats` WHERE `cats` = '$cat' ORDER by `id`");
while($r=mysql_fetch_array($sql)) {
$cat = $r['cat'];
$id = $r['id'];

echo "<tr class='headline'><td width='80%'><b><font color='white'>-$cat</font></b></td><td width='20%'><b><font color='white'>Автор</font></b></td></tr>";

$sqll = mysql_query("SELECT * FROM '$mysql_table' WHERE cat='$cat' ORDER by `postid` DESC ") or die (mysql_error());
while ($s=mysql_fetch_array($sqll)) {
$author=$s['author'];
$title=$s['title'];
$id=$s['postid'];

echo "<tr>";
echo "<td width='80%'>";
echo "-<b><a href='index.php?pp=message&id=$id'><font color='green'>$title</font></a></b>";
echo "        $lock_unlock";
echo "</td>";
echo "<td width='20%'><b><font color='green'>$author</font></b></td>";
echo "</tr>";
}
}
print "</table>";
echo "Страница: ";
echo $nomeranastranici;
?>

Така ?
 

Горе