Jump to content

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


Oxymen

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!!!
Link to comment
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)
Link to comment
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]
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.