Jump to content

Recommended Posts

If I want to enter some values into an array like so:

 

$newarray = array($_POST['v1'], $_POST['v2'], $_POST['v3']);
$commaseparated = implode(',', $newarray);
mysql_query("insert into table set valuess='$commaseparated'") or die('error: '.mysql_error());

 

Is there a way of having a value as 0? Ie sometimes the values will just be v1 and v2 and v3 will not be needed.

 

I hope this makes sense!

Link to comment
https://forums.phpfreaks.com/topic/156779-array-question/
Share on other sites

Basically the amount of fields will be different each time.

 

Please ignore the sql statement for the time being, just quickly showing what I was tring to achieve.

 

as an example, say I am uploading details of a book, the book has its own unique identifier in a database, and an author. I then want to upload the chapter names, obviously each book has a different amount of chapters.

 

Hope that makes more sense

 

Link to comment
https://forums.phpfreaks.com/topic/156779-array-question/#findComment-825617
Share on other sites

Why?

 

When its inserted into the database it will all go in one field.

Say you want to look up what book has a certain chapter name. You'll have to grab ALL the entries, implode the string, loop the array.

 

Though if you had to say that, then you need to take a DB design course because you didn't know why. Not to be mean, but I'm just telling it like it is. Read Crayon Violent's post.

Link to comment
https://forums.phpfreaks.com/topic/156779-array-question/#findComment-825665
Share on other sites

Ok,

 

well I dont want to be able to search the field, I just want to echo the result. Perhaps I should just have the user add all the chapters in a text box, one per line, store them all in one field and tehn just echo teh field?

Yeah. You would have one entry in the DB for each chapter.

 

The table should be:

id PRIMARY_KEY

book_id

chapter_name

Link to comment
https://forums.phpfreaks.com/topic/156779-array-question/#findComment-825691
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.