regoch Posted March 4, 2010 Share Posted March 4, 2010 Hail! I try to get in my gallery like on facebook example "Image 3 from 24". I use: <?php include ("admin/connect.php"); $rezultat=mysql_query("SELECT * FROM slike ORDER BY id_slike DESC"); $broj_slika=mysql_numrows($rezultat); echo $broj_slika; ?> to get total row number, but i can't get single row number to work. I try with this: <?php include ("admin/connect.php"); $id_slike=$_GET['id_slike']; $sql = mysql_query("SELECT * FROM slike"); $rownr=0; while($row=mysql_fetch_assoc($sql)) { $rownr++; echo $rownr; } ?> This is database: CREATE TABLE IF NOT EXISTS `slike` ( `id_slike` int(11) NOT NULL AUTO_INCREMENT, `picture_name` varchar(150) COLLATE latin1_general_ci NOT NULL DEFAULT '', `picture_size` varchar(50) COLLATE latin1_general_ci NOT NULL DEFAULT '', `id_galerije` int(11) NOT NULL, PRIMARY KEY (`id_slike`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; Hope you get what is my problem! Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/ Share on other sites More sharing options...
schilly Posted March 4, 2010 Share Posted March 4, 2010 $broj_slika=mysql_num_rows($rezultat); spelling mistake Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021535 Share on other sites More sharing options...
regoch Posted March 4, 2010 Author Share Posted March 4, 2010 That first code work, problem is in second code! Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021563 Share on other sites More sharing options...
schilly Posted March 4, 2010 Share Posted March 4, 2010 second part looks fine. <?php include ("admin/connect.php"); $id_slike=$_GET['id_slike']; $sql = mysql_query("SELECT * FROM slike"); $rownr=0; while($row=mysql_fetch_assoc($sql)) { $rownr++; echo $rownr; } ?> what does it output? This is also a quick way to get the number of rows. $num_row = mysql_result(mysql_query("SELECT count(id_slike) FROM slike"),0); Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021602 Share on other sites More sharing options...
regoch Posted March 4, 2010 Author Share Posted March 4, 2010 second part looks fine. <?php include ("admin/connect.php"); $id_slike=$_GET['id_slike']; $sql = mysql_query("SELECT * FROM slike"); $rownr=0; while($row=mysql_fetch_assoc($sql)) { $rownr++; echo $rownr; } ?> what does it output? that code show me "1 2 3 4 5 6 7 8 9 10 etc" number of rows in query. but I wont to get just number of selected row that sho picture (pictre on croatian is slika). not id_slike because picture are been deleted so id_slike don't work to this. Like on gallery when it shows Image 4 from 24 and when I click next Image 4 from 24 etc. number of rows work fine, but selected row is a problem. Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021622 Share on other sites More sharing options...
Zane Posted March 4, 2010 Share Posted March 4, 2010 instead of setting a counter.. use mysql_fetch_array to keep a count. something like $row = mysql_fetch_array($myResult, MYSQL_NUM) NOTE the "MYSQL_NUM" .... this tells mysql_fetch_array to only use numbers and not field names... this way you can loop through your results... like this foreach(($row = mysql_fetch_array($result, MYSQL_NUM)) as $fieldNum=>$value) { echo $fieldNum++ . " -> " . $value; } and you're... current number will ALWAYS be the $fieldNum PLUS 1... Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021651 Share on other sites More sharing options...
regoch Posted March 4, 2010 Author Share Posted March 4, 2010 include ("admin/connect.php"); $id_slike=$_GET['id_slike']; $sql = mysql_query("SELECT * FROM slike WHERE id_slike=$id_slike"); foreach(($row = mysql_fetch_array($sql, MYSQL_NUM)) as $fieldNum=>$value) { echo $fieldNum++ . " -> " . $value; } I try you code but it show information from database about my picture, not the number of row. I get Image "information about picture" from 22 instead Image 3 from 22. Thanks for trying! Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021692 Share on other sites More sharing options...
regoch Posted March 5, 2010 Author Share Posted March 5, 2010 anything? Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021899 Share on other sites More sharing options...
greatstar00 Posted March 5, 2010 Share Posted March 5, 2010 $q=mysql_query("select count(*) as c from slike where id<={$id_slike}"); //assume u order in asc $num=mysql_fetch_array($q); echo 'Image '.$num['c'].' From '.$broj_slika; Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021904 Share on other sites More sharing options...
regoch Posted March 5, 2010 Author Share Posted March 5, 2010 THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/#findComment-1021948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.