lu13cky Posted May 20, 2010 Share Posted May 20, 2010 I'm attempting to output a unique number for each row, which - I can obviously do with assigning the numbers in the database.However, to make my life easier, I'm trying to figure out how I would use COUNT or something similar to do this for me.And just so you can see what I'm talking about: http://www.stephanierhoades.net/view.php?id=portraitsthe numbering is fine, until you click on another album (Weddings has images up so you can see). The count does not start over (because why should it when the numbers are assigned). Of course this could cause some major headaches for visitors to my site trying to find 1-4 on the wedding photos :)I've tried num_rows but then realized - duh. That is not what I want.Any suggestions or help would be greatly appreciated. Link to comment Share on other sites More sharing options...
ShadowMage Posted May 20, 2010 Share Posted May 20, 2010 Perhaps some code might help. Link to comment Share on other sites More sharing options...
lu13cky Posted May 20, 2010 Author Share Posted May 20, 2010 For the actual numbered links: while ($row = mysql_fetch_assoc($result)) {$rowcolor = rowcolor($count);$id = $row['id']; $name = $row['name']; $photo = $row['photo'];$number = $row['number'];?> <li><a class="boxed" href="#<?php echo $number; ?>"><?php echo $number; ?></a></li> For the images: while ($row = mysql_fetch_assoc($result)) {$rowcolor = rowcolor($count);$id = $row['id']; $name = $row['name']; $photo = $row['photo'];$number = $row['number'];<a name="<?php echo $number; ?>" id="<?php echo $number; ?>"></a><img class="img" src="lgimages/<?php echo $photo; ?>.jpg"> Link to comment Share on other sites More sharing options...
chibineku Posted May 20, 2010 Share Posted May 20, 2010 If you are using count in your query, like: SELECT COUNT(id) FROM tableName, then you fetch the value of count in $row[COUNT(id)]. I don't know if that's what you mean or at all helpful. Link to comment Share on other sites More sharing options...
ShadowMage Posted May 20, 2010 Share Posted May 20, 2010 Can you post the query? The more code you provide the more likely someone will be able to help you find a solution. Link to comment Share on other sites More sharing options...
lu13cky Posted May 20, 2010 Author Share Posted May 20, 2010 Can you post the query? The more code you provide the more likely someone will be able to help you find a solution.yup :)The query is really simple - not much to it.$result =mysql_query("SELECT * FROM photo WHERE id = '$id'") or die('Could not run query because: '.mysql_error()); I currently have the ID set for each album name (ie. Portraits, Wedding, etc) Link to comment Share on other sites More sharing options...
ShadowMage Posted May 20, 2010 Share Posted May 20, 2010 So is $number the primary key in your database then?What you could do instead of printing the number associated with the image is to have a counter within your while loops. That way when you go to a new album the counter will be reset.Something like: while ($row = mysql_fetch_assoc($result)) {$rowcolor = rowcolor($count);$id = $row['id'];$name = $row['name'];$photo = $row['photo'];$number = $row['number'];$imgNum = 0;?> <li><a class="boxed" href="#<?php echo $number; ?>"><?php echo $imgNum++; ?></a></li> Link to comment Share on other sites More sharing options...
lu13cky Posted May 20, 2010 Author Share Posted May 20, 2010 I had to do some finagling - but! It worked.Thank you so much for your help :)the end coding turned out to be this: $result =mysql_query("SELECT * FROM photo WHERE id = '$id'") or die('Could not run query because: '.mysql_error());$imgNum=1;while ($row = mysql_fetch_assoc($result)) {$id = $row['id']; $name = $row['name']; $photo = $row['photo'];$number = $row['number'];?> <li><a class="boxed" href="#<?php echo $number; ?>"><?php echo $imgNum; ?></a></li><?$imgNum++;}?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.