Page 1 of 1
Book Index
Posted: Tue Nov 04, 2008 5:31 am
by Arsench2000
Hello, Ive created a db for books,
In my form for book index register I dont know how many text boxes I have to put or how to do, when every time the index data is different, for example:
book_index
id,sub_id,chapter (table for chapters)
book_sub_index (table for a sub chapters)
id,sub_id(which will be = with book_index sub_id), sub_chapter.
in the form where the user will register the book index, I dont know how many textboxes or into db how many fields creat for this, becouse every time this will register different quantity pages or chapter etc...
Any advice and help please?
Thank you.
Re: Book Index
Posted: Tue Nov 04, 2008 6:09 am
by aceconcepts
You could use a for loop based on a user entry.
e.g. use a text field so the user can enter in the quantity of fields they desire. Then use this quantity in the for loop:
Code: Select all
for($x=0; $x<$field_qty; $x++){
//display text boxes
}
With regard to the database, you could just use a sepearte record for each entry made by the user.
Re: Book Index
Posted: Tue Nov 04, 2008 6:34 am
by papa
You might want to save every chapter on a new table row depending on what the actual pages does.
[chapter]
id book_id chapter_text
[chapters]
id chapter_id name
Might want to have some kind of chapter # so you can change the order of the chapters afterwards.
Re: Book Index
Posted: Tue Nov 04, 2008 8:43 am
by Arsench2000
aceconcepts wrote:You could use a for loop based on a user entry.
e.g. use a text field so the user can enter in the quantity of fields they desire. Then use this quantity in the for loop:
Code: Select all
for($x=0; $x<$field_qty; $x++){
//display text boxes
}
With regard to the database, you could just use a sepearte record for each entry made by the user.
thank you very much friend for your replay, as Im a new in php world, can you please give the example with a little more details?
regards
Re: Book Index
Posted: Tue Nov 04, 2008 9:10 am
by aceconcepts
Code: Select all
for($x=0; $x<$field_qty; $x++){
//display text boxes
}
From the for loop above, if the user entered 3 into the $field_qty form field then the for loop will loop 3 times.
This is how a for loop typically works: for(set the counter; number of times to loop; increment counter)
if you never really know how many fields are required you could simply have the user specify how many they need - just like i've illustrated about with $field_qty.
Do you understand this?