View Single Post
Old 12-04-2008, 10:38 PM   #1 (permalink)
tony
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default need help with retrieving

I've used this code before, and has worked. But now I can't understand what is the problem.

I have a code to test my queries for a website I am doing. This is the code:

PHP Code:
$a=array();
try{
    
$q=mysql_query('SELECT ArticleID FROM articles') or die(mysql_error());
    echo 
mysql_affected_rows();
    echo 
'<br />';
    
var_dump($q);
    echo 
'<br />';
    while(
$res=mysql_fetch_assoc($q));
        
array_push($a$res);
    
var_dump($a);
    echo 
'<br />';
}catch(
Exception $e){
  echo 
$e->getMessage();
  exit();

the echo and var_dump statements I used them to see what is the problem, but still can't figure out. The output I get is this:

Code:
8
resource(15) of type (mysql result)
array(1) { [0]=> bool(false) }
I know I have 8 entries in the table, because I also ran the query in the mysql console and got this:

Code:
mysql> SELECT ArticleID FROM articles;
+----------------------------------+
| ArticleID                        |
+----------------------------------+
| 32d9b19297370a3f53f22d5d5715c847 | 
| 35d97569c36ade68499ea6f51d88a20a | 
| 6981086eb26c319ad7631b7d2f30618d | 
| 81967e633319c72e44284884157ad432 | 
| 874820c3267d7f0a94bf9a89baf83508 | 
| a7b39088eb9a13de840383ff27e24ac4 | 
| cf47d07a4f6d371f863a41e8e24bc285 | 
| e13d693f6ecd117aeb5ad9d04324e558 | 
+----------------------------------+
8 rows in set (0.00 sec)
I still don't know why I don't get an array of arrays that are the fetched rows. any idea?

If you need more info this is the articles table:

Code:
mysql> SHOW COLUMNS FROM articles;
+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ArticleID   | varchar(32)  | NO   | PRI | NULL    |       | 
| Title       | varchar(255) | NO   |     | NULL    |       | 
| Description | text         | YES  |     | NULL    |       | 
| Content     | text         | NO   |     | NULL    |       | 
| MediaID     | varchar(32)  | NO   | UNI | NULL    |       | 
| UserID      | varchar(32)  | NO   |     | NULL    |       | 
| DateTime    | datetime     | NO   |     | NULL    |       | 
+-------------+--------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
This used to be simple to me, but now it is stressing me out and delaying the final product. thanks for the help in advance.
tony is offline  
Reply With Quote