Jump to content

Archived

This topic is now archived and is closed to further replies.

Oxymen

Get last row with content in spesific column. And insert data into "holes"

Recommended Posts

Hi. I am making a mysql table where there is always a posibility that a cell is empty. i will try to illustrate:

[table]
[tr]
[td]Firstname[/td][td]Lastname[/td]
[/tr]
[tr]
[td]Bob[/td][td]Larsen[/td]
[/tr]
[tr]
[td]Lyle[/td][td][/td]
[/tr]
[tr]
[td]Brian[/td][td]Holmes[/td]
[/tr][/table]

I want my form to insert the next lastname that is submitted into row two as this is empty.
The first and last names have no relationship as this is only a database of names, and I dont
want to make one table for firstnames and one table for second names. but still I dont want
to have holes in the table.
I also need a way to get the last row of first and second name individualy, not just the last row
in the table, to hinder that empty rows are outputted later.

Thanks a lot!!!

Share this post


Link to post
Share on other sites
[quote]... but still I dont want to have holes in the table.[/quote]

Why not? Who cares?  It's easier to code around datafields containing nothing than try looking to fill gaps in a database (which is one step away from trashing a perfectly good database)

Share this post


Link to post
Share on other sites
Wouldn't it then be better then to have table defined as

[pre]names
--------
id int not null auto_increment primary key,
nametype char,                                  // F or L (first or last name)
name varchar(20)[/pre]

You then have no holes and get the last lastname added with
[code]SELECT name FROM names
WHERE nametype = 'L'
ORDER BY id DESC
LIMIT 1[/code]

Share this post


Link to post
Share on other sites

×

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.