1 (edited by freddykgb 2006-03-05 23:28)

Topic: Trouble fetching info from db

Here's my code, and i don't know why, but i don't get any results from the echo

<?php

        // Nombre de latest post à afficher
        $count = 8;

        // Compteur
        $i = 0;

        // Connexion à la bd
        $connexion = mysql_connect('localhost', 'root', '******');

        // Si la connexion a échoué
        if (!$connexion)
        {
            die ('Connexion à MySql impossible : ' . mysql_error());
        }

        $db_selected = mysql_select_db('forum');
        if (!$db_selected)
        {
            die('Connexion à la base de données impossible : ' . mysql_error());
        }

        // Requête sql
        $query = "SELECT subject, last_post FROM topics WHERE forum_id = 1 AND moved_to IS NULL ORDER BY last_post DESC";

        // Variable des résultats
        $results = mysql_query($query);

        // Si aucun résultat erreur
        if (!$results) 
        {
           $message  = 'Invalid query: ' . mysql_error() . "\n";
           $message .= 'Whole query: ' . $query;
           die($message);
        }

        if (mysql_num_rows($results) == 0) {
           echo "No rows found, nothing to print so am exiting";
           exit;
        }

        // Tant qu'il reste des résultats et que le nombre de posts
        while ($row = mysql_fetch_assoc($results) && $i < $count)
        {
            // Transfert le timestamp en date
            //$date = getdate($row["posted"]);

            echo $row["subject"];

            // Incrémente le compteur
                        $i++;
        }

        mysql_close($connexion);
        ?>
A new poker community is rising : see for yourselft at unbluffed.com

Re: Trouble fetching info from db

well, i found the error : for some reason, my php doesnt support the && as a logical and ???

A new poker community is rising : see for yourselft at unbluffed.com