php - Counting rows in PDO -


this function counts songs specified album using pdo.

i tried looking @ what's wrong nothing. searched here , bing, nothing.

function artist_count_songs($id) {     global $db;     $count = $db->prepare("select count(`song_id`) `songs` `album_id` = :id");     $count = $count->execute(array(':id' => $id));             echo $count; } 

is there i'm missing? tried rowcolumn still nothing

database structure

set sql_mode="no_auto_value_on_zero"; set time_zone = "+00:00";  create table if not exists `songs` (   `song_id` int(11) not null auto_increment,   `album_id` int(11) not null,   `name` varchar(60) collate utf8_unicode_ci not null,   `download_url` varchar(1024) collate utf8_unicode_ci not null,   primary key (`song_id`) ) engine=myisam  default charset=utf8 collate=utf8_unicode_ci auto_increment=3 ;  insert `songs` (`song_id`, `album_id`, `name`, `download_url`) values (1, 1, 'بحبك اه', 'downloads/tamerhosny/b7bk-ah.mp3'), (2, 1, 'بحبك اه', 'downloads/tamerhosny/b7bk-ah.mp3'); 

edit 1

    // count songs total album     function artist_count_songs($album_id) {         global $db;                 $stmt    = $db->prepare("select count(`song_id`) `songs` `album_id` = :album_id");         $success = $stmt->execute(array(':album_id' => $album_id));         list($count) = $stmt->fetch();         echo '<th>';         echo $count;         echo '</th>';     } 

$count boolean return value of execute method.

$stmt    = $db->prepare(     "select count(`song_id`) `songs` `album_id` = :id" ); var_dump($stmt);  $success = $stmt->execute(array(':id' => $id)); var_dump($success);  list($count) = $stmt->fetch(); var_dump($count);     

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -