0

Please i have an issue with my code. I intend to select all details in my database and loop through to create a table. But i keep getting this error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\donation_details.php on line 10 No donation records found

Please kindly assist. i'll appreciate any assistance i get. Thanks

$connect = mysql_connect("localhost","hifee","kalimat","hifee");
if(!$connect) die('Unable to fetch data');
else{
$donation = array();
$query = "SELECT * FROM tx_transaction";
echo $query;
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
    $donation[] = $row;
}
$total_records = count($donation);
if($total_records > 0){
    echo '<table>';
    echo    '<tr>Transaction ID</td>
                <td>Amount donated(=N=)</td>
                <td>Donation date</td>
                <td>Donation status</td>
                <td>Response code</td>
                <td>Meno</td>
                <td>Response details</td>
                <td>Donor\'s email</td>
            </tr>';
    foreach($donation as $value){

        echo    '<tr />
                    <td>'.$value['tx_id'].'</td>
                    <td>'.number_format($value['tx_amount'],2).'</td>
                    <td>'.$value['tx_date'].'</td>
                    <td>'.$value['tx_status'].'</td>
                    <td>'.$value['tx_response_code'].'</td>
                    <td>'.$value['tx_memo'].'</td>
                    <td>'.$value['tx_response_details'].'</td>
                    <td>'.$value['tx_buyer_email'].'</td>
                </tr>';
    }

    echo '</table>';
}else echo 'No donation records found';
}
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132
Ifeoluwapo Ojikutu
  • 69
  • 1
  • 1
  • 12
  • Your query most likely failed. – Matt Sep 10 '13 at 16:20
  • First, your use of mysql functions is deprecated and will eventually be removed from PHP. I doubt you want to develop something that will be unsupported later. Second, mysql_connect is followed by mysql_select_db to get the database opened. Third, see if the mysql_query throws an error by following the mysql_query by printing mysql_error(). – kainaw Sep 10 '13 at 16:22
  • ADD `$result = mysql_query($query)or die(mysql_error());` this line and see that will surly give you error – Dipesh Parmar Sep 10 '13 at 16:22
  • *PSA:* The `mysql_*` functions are [deprecated in PHP 5.5](http://php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated). It is not recommended for writing new code as it will prevent you from upgrading in the future. Instead, use either [MySQLi](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/book.pdo.php) and [be a better PHP Developer](http://jason.pureconcepts.net/2012/08/better-php-developer/). – Jason McCreary Sep 10 '13 at 16:23

0 Answers0