Jump to content

Recommended Posts

Hello guys, im using this code atm and it's working, but the new rows created are put in the end of the table. I want them to stack up from the beginning pushing older rows down. What should i do to make that work? :)

 

 

<?php

$con = mysql_connect("localhost","*****","*******");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("ananaz_se", $con);

 

$sql="INSERT INTO stuff (adult, namn, url)

VALUES

('$_POST[adult]','$_POST[namn]','$_POST')";

 

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 row added";

 

mysql_close($con)

?>

Well i have a field "id" a INT NOT NULL auto_increment

and i want to call for example the data from the row with id 1 in a script. Then in another script i want to easily be able to "update" the rows by adding a new row on top so that row will display as id 1.

Well i have a field "id" a INT NOT NULL auto_increment

and i want to call for example the data from the row with id 1 in a script. Then in another script i want to easily be able to "update" the rows by adding a new row on top so that row will display as id 1.

 

Changing around the 'id' column defeats the purpose of having an auto incremented column.  Why does the new row have to be on top?  If you insert it normally you can easily find the most recent row.  Maybe I'm not understanding completely but I don't think inserting a new row on top every time would do any good, probably harm.

1. inserting and updating are 2 different activities

2. an unique auto-increment field serves a very important function

3. to get the most recent row added simply query - order by id DESC limt 1 will return the most recently added row

4. if you put a date_edited field in the table and update it whenever a row is edited you can use that to get the most recently updated

Ok I might be explaining it wrong. hmm..

 

I have a website submitting links just for fun like this:

 

<Website>

 

Link 1  (lolcats)

Link 2  (rageguy)

Link 3  (something scary)

 

Then i have post.html (what will be acceptable only from my ip later) with a form that leads to "post.php" submitting a new row in my mysql server.

 

I have names on the Links and they are named through mysql data.

So the Link 1 will automatically take the name of the name field where the id is 1, and so on with Link 2..

 

The idea is that i should be able to easily update the website with a new name and link by making the current Link 1 data become Link 2 data ect..

 

So if i use the post.html and add a new it will look like this.

 

<Website>

 

Link 1  (something new and awesome)

Link 2  (lolcats)

Link 3  (rageguy)

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.