помищ за извичане на данни от базата

pweb

Registered
значи този код ми извича всички записи от базата
Код:
<?
$connection = mysql_connect("localhost","dbusername","dbpassword")
or die("no connect");
mysql_select_db("dbname");
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

// Define the number of results per page
$max_results = 5;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results); 

// Perform MySQL query on only the current page number's results

$sql = mysql_query("SELECT * FROM articles LIMIT $from, $max_results");
while (list ($id , $title,$text, )=mysql_fetch_array ($sql)) {
$text_limit="$text";
$text_limit=substr($text,0 , 50);
echo "<p><a href=procheti.php?id=$id>$title</a></p>$text_limit";

}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM articles"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center><p><br />";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">íàïðåä>></a>";
}
echo "</p></center>";
?>
как може да стане до извлича данните от определена категория
ето и базата
Код:
CREATE TABLE articles (
  id INT PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(100) DEFAULT NULL,
  text TEXT,
  category INT(8) NOT NULL DEFAULT '0',
);
самите категорий се записват в друга таблица
 
Код:
<?
$connection = mysql_connect("localhost","dbusername","dbpassword")
or die("no connect");
mysql_select_db("dbname");
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
$cat=$_GET['cat'];
// Define the number of results per page
$max_results = 5;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number's results

$sql = mysql_query("SELECT * FROM articles WHERE category LIKE '$cat' LIMIT $from, $max_results");
while (list ($id , $title,$text, )=mysql_fetch_array ($sql)) {
$text_limit="$text";
$text_limit=substr($text,0 , 50);
echo "<p><a href=procheti.php?id=$id>$title</a></p>$text_limit";

}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM articles"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center><p><br />";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">iai?aa>></a>";
}
echo "</p></center>";
?>
 
да почти е така добавя се още малко код и се получава
това го направих обече като направя нов запис ми го изкарва наи накрая как да стане да го показва най отпред
 
Код:
 <?
$connection = mysql_connect("localhost","dbusername","dbpassword")
or die("no connect");
mysql_select_db("dbname");
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
$cat=$_GET['cat'];
// Define the number of results per page
$max_results = 5;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number's results

$sql = mysql_query("SELECT * FROM articles WHERE category LIKE '$cat' ORDER BY id DESC LIMIT $from, $max_results");
while (list ($id , $title,$text, )=mysql_fetch_array ($sql)) {
$text_limit="$text";
$text_limit=substr($text,0 , 50);
echo "<p><a href=procheti.php?id=$id>$title</a></p>$text_limit";

}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM articles"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center><p><br />";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">iai?aa>></a>";
}
echo "</p></center>";
?>

ORDER BY id DESC...
 

Back
Горе