Jump to content

[SOLVED] Assigning the maximum value to the minimum and so fourth?


proud

Recommended Posts

I'm trying to write a script that will allow me to reverse the maximum values

with the minimum values, for example lets assume I have a table in which I have got two fields named (photo_id , photo_name ) and there are 30 photos In this table ; now I'm trying to assign the photo_id with the value equal to 1 a value of 30, and the photo_id with the value equal to 2 a value of 29 and so going on...

 

To make it more clear:

1=30

2=29

3=28

4=27

  .

  .

  .

etc...

 

So what is the code that will allow me to do this?

 

 

maybe this is what you're looking for:

<?php
        $sql = "SELECT photo_id FROM your_table ORDER BY ASC";
        $query = mysql_query($sql);

        $i = mysql_num_rows($query);
        while($row = mysql_fetch_array($query)){
                $sql = "UPDATE your_table SET photo_id = '". $i ."'";
                mysql_query($sql);
                $i--;
        }
?>

Archived

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

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