You are here: counting total in/after while loop « PHP Programming Language « IT news, forums, messages
counting total in/after while loop

Posted by Ja NE on 03/01/06 16:38

(as first, I have to apologize for my clumsy English...)

here is my situation:
// I'm stupid... sort of. ;)

I would like to see how many pictures have "lost" their albums - I have
table "album" with some id, I have table "photo" with pict's id and
album's id so I can know where the picture belong, but sometimes some
users delete their album form database without moving pictures to
different (existing) album.
for the beginning I would like my members to see how many of those
so, I have those few queries:

<?
$q_total = "SELECT count(*) FROM photo";
$r_total = mysql_query($q_total) or die("q_total died [$q_total]");
list($total) = mysql_fetch_array($r_total);

$q_album = "SELECT id FROM album";
$r_album = mysql_query($q_album) or die("q_album died [$q_album]");
while(list($al_id) = mysql_fetch_array($r_album)) {
$q_exist = "SELECT count(*) FROM photo WHERE album=$al_id";
$r_exist = mysql_query($q_exist) or die("q_exist died [$q_exist]");
list($exist) = mysql_fetch_array($r_exist);
}

$lost = $total - $exist;
?>

I am aware that with this last line of code I'm getting only number of
existing pics in very last album, not in all albums... I know that I
should use something like foreach(but what?)

so... can, please, anyone help me with that?
tnx

--
Ja NE
http://fotozine.org/?omen=janimir
--

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация