Hi Jon, and Howard,
(comments interposed, below)
> Try using something like
> $getlist = mysql_query("SELECT id FROM yourdb",$dbconnectetc);
> $numrows = mysql_num_rows($getlist);
> echo "$numrows\n";
>
> This will give you the number of records in your db.
> If you use autoincrement for the id field your will not have to
> worry about your ++.
>
> If you delete any records numrows will always be correct.
=this is correct, but COUNT(*) is optimised/more efficient (RTFM: 6.3.7 Functions for
Use with GROUP BY
Clauses)
> --------------------------------------------
> First off, sorry for the newbie question... :(.
>
> I want to be able to query the database and find the record with the
> highest ID value. Example... each row ideally has an incremented integer
> ID (1, 2, 3, 4...) but I am running into problems when I try and delete
> a row (let's say row 2). My PHP currently selects all of the rows and
> formulates the ID off of that... This I found out is bad because when I
> delete row 2 the query says there are 3 rows so my PHP will try to make
> the ID = 4. I just need the code to find the highest ID so I can ++ it.
> Sorry again for the easy question!
=no need to apologise, we all have to start somewhere.
=It is an FAQ. By asking it you indicate that you don't (yet) understand the
philosophy of the AUTO_INCREMENT
facility. It is there to provide an ID for new rows of data, not to be a 'count' of
the rows. If you consider
that this ID may be used as a key into this table's data from another table (foreign
key), then you will realise
that changing ID values to reflect intermediate deletions is less than logical. (RTFM:
3.5.9 Using
AUTO_INCREMENT, although it doesn't seem to get into this point - the annotated
comments are worth a read
though). I've just a had a quick look to see where the manual discusses the
'philosophy' and have come up
empty - perhaps someone else can steer you right, if you need more.
=It is worth reading through PHP's large collection of built-in MySQL_ functions.
There are specific functions
that will return various 'numbers of rows' to the script to suit various situations.
=Regards,
=dn
=Regards,
=dn
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php