Book Index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Arsench2000
Forum Commoner
Posts: 38
Joined: Sat Sep 15, 2007 8:18 pm

Book Index

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Book Index

Post 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.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Book Index

Post 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.
Arsench2000
Forum Commoner
Posts: 38
Joined: Sat Sep 15, 2007 8:18 pm

Re: Book Index

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Book Index

Post 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?
Post Reply