Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 Oxymen

Oxymen
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 02 September 2006 - 08:40 PM

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













FirstnameLastname
BobLarsen
Lyle
BrianHolmes


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!!!

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 02 September 2006 - 11:05 PM

... but still I dont want to have holes in the table.


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)
Legend has it that reading the manual never killed anyone.
My site

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 02 September 2006 - 11:26 PM

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
SELECT name FROM names
WHERE nametype = 'L'
ORDER BY id DESC
LIMIT 1

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 Oxymen

Oxymen
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 02 September 2006 - 11:54 PM

Thanks Barand, I didnt think of that sollution, that will work.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users