Jump to content

Counting rows (and a little more) [Solved]


lu13cky

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...