Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL] Problem z wybieraniem danych z bazy
Buła
post
Post #1





Grupa: Zarejestrowani
Postów: 35
Pomógł: 0
Dołączył: 21.01.2009

Ostrzeżenie: (0%)
-----


Witam.

Mam pewien problem. Napisałem skrypt który wybiera newsy z bazy danych i wyświetla je na stronie.
Jednak nie działa on tak jak powinien - nigdy nie wyświetla najnowszego newsu. Wyświetla przedostatni i starsze, ale nigdy ten najnowszy który dodałem.

Skrypt wygląda tak:
Kod
    $news_result = mysql_query("SELECT * FROM gbsite_news ORDER BY news_id DESC");
    $news_data = mysql_fetch_array($news_result);
    if (mysql_num_rows($news_result) != 0)
    {
        while ($news_data = mysql_fetch_array($news_result))
        {

            $user = $news_data['news_author'];
            $user_result = mysql_query("SELECT `user_id` FROM gbsite_users WHERE user_name = '$user'");
            $user_data = mysql_fetch_array($user_result);

            echo "<br>
            <img src='theme/img/layout/news_cat.gif' align='left' border='0' width='128' height='118'>
            <font size='4'>".$news_data['news_title']."</font> <br>
            <img src='theme/img/layout/news_line.gif' border='0'> <br>
            ".$news_data['news_text']." <br>
            <p align='right'><font color='#808080' size='2'> Dodano: ".$news_data['news_time'].", ".$news_data['news_date']."<br>Napisał: <a href='showprofile.php?id=".$user_data['user_id']."'>".$news_data['news_author']."</a> </font> <br> <br>
            <center><br><img src='theme/img/layout/small_sep.gif' border='0'></center>";
        }
    }


Gdy dodam tutaj dwa dolary:
$news_data = mysql_fetch_array($$news_result);
to wyświetla wszystkie newsy, razem z najnowszym. Ale wtedy dodatkowo na górze wywala błąd:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Wiecie może jak to naprawić?

Ten post edytował Buła 23.06.2009, 08:52:41
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 02:23