Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/194154-showing-number-of-picture-in-gallery/
Share on other sites

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);

 

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.

 

 

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...

	
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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.