Jump to content

Simple Functions holding me back... Please Help!


released

Recommended Posts

I am in the final stages of a project I have been working on for about 6 months. It is just a basic dynamic website where the user can login and edit the website. I am using Flash, PHP and MySQL. The problem that I have faced is that when I add or delete and entry, the auto_incremented `id` field may cause the entry to be out of order. When I add an entry, it will add it in the middle or beginning of the table. The result is a non-ascending set of values for `id`, when I need the entries to be in order. My scripts are as follows:

// Select
$id= $_POST['id']; //Retrieved from Flash
$limit= $_POST['limit']; //Retrieved from Flash
$query= "SELECT * FROM `news` LIMIT ".$id.",".$limit.";
$data= mysql_query($query);

//How can I incorpatate an efficient 'SORT BY' function to automatically sort the `id` field every time I retrieve an entry? Or is there a way that I can set the `id` field to automatically do this, such as making it a Primary, Index or Unique?

//Insert
$date= $_POST['date'];
$entry= $_POST['entry'];
$query= "INSERT INTO `news` (`id`, `date`, `entry`) VALUES ('', '$date', '$entry');
mysql_query($query);

//Is there a way that I can automatically add an entry to the end of the table with the auto-incremented value?

//Delete
$id= $_POST['id'];
$query= "DELETE FROM `news` WHERE `id`= ".$id;
mysql_query($query);

//When I delete an entry, is there a way that I can have all the entries that come after the row being deleted automatically reset their numbers to adjust to the missing id number? So if I delete entry '7', entry '8' will become entry 7, and entry '9' will become 8 and so on and so forth?

Thanks Very Much for your time,
Jesse
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.