Hi all, im sure this is a small problem so here goes..... I have a form that will insert data into my MySQL database, but the data is added to the end, how can I get the data to be added at the start of the database.... code below from the submit bit of the form

Thanks in advance
Lee

<?php

if ($submit) {

// process form

$db = mysql_connect("XXXXX", "XXXXXX", "XXXXXXX") or die("Could Not Connect To The Database. <br>" . mysql_error());

mysql_select_db("XXXXXXX",$db) or die("Could Not Select The Proper Database. <br>" . mysql_error());

$ident = $POST['ident'];
$town = $
POST['town'];
$name = $POST['name'];
$info = $
POST['info'];
$url = $POST['url'];
$simg = $
POST['simg'];

$sql = "INSERT INTO tablename(ident, town, name, info, url, simg) VALUES ('$ident','$town','$name','$info','$url','$simg')";

$result = mysql_query($sql);

if($result)

{

echo "Data Properly Inserted";

}

else

{

echo "An Error occured while trying to process your information.";

 print ("<br>" . mysql_error()); 

}

echo $sql ;

echo "Thank you! Information entered.\n";

}

else

{

// display form

?>

    It doesn't matter how you add it, just do aproper order by when pulling it out.

      Does a table have a defined order?

      I may be mistaken, but my understanding of relational databases is that table rows have no defined order.

      So there is no begining or end, or row #4.

      If you don't specify sorting MySQL can return the results in any order it choses and you have no righ to complain about this violating any standard.

      If you need the results in a particular order you will have to create a timestamp or sequence number and use that to sort when you perform your query.

        There is a semi-defined order, but I don't think MySQL has it. Oracle however has an internal numbering system you can call with ROWID.

          Thanks guys for your advice Ive learnt something new today!

          Ive now added the timestamp column and when I add new record it does give it a "timestamp" what i now want it to do is to display the latest 3 entries to the database... to do a sort of whats new section on my home page. I have code so far that just gives me the first 3 entries in the database because obviously the time stamp on the entries already in the db are now 000000000 etc

          $query = "SELECT * FROM gzdata1 ORDER by dates LIMIT 0, 3;";

          how do I get it to pull up the 3 latest entries?

          Any help would be great, thanks

          Lee

            Just have to order descending...

            $query = "SELECT * FROM gzdata1 ORDER by dates DESC LIMIT 0, 3;";

              Big thanks for that, im sorted.

              Cheers
              Lee

                Write a Reply...