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?

 

 

Link to comment
Share on other sites

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--;
        }
?>

Link to comment
Share on other sites

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.