UnknownPlayer Posted October 17, 2010 Share Posted October 17, 2010 How can i save array from inputs, witch is $igraci and it have 5 values, to mysql base, i tryed but in mysql it shows Array. This is form: <form action="dodaj_klan.php" method="post" > <p> <label>Naziv klana:</label> <input name="naziv" type="text" size="20%" /> <label>Web Sajt:</label> <input name="website" type="text" size="20%" /> <label>E-Mail:</label> <input name="email" type="text" size="20%" /> <br /><br /> <label>Igraci klana(5):</label> <input name="lider" type="radio" value="1" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="2" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="3" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="4" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="5" /> <input name="igraci[]" type="text" size="20%" /> <label><i>(obelezi lidera klana)</i></label> <br /><br /> <input class="button" type="submit" name="submit" value="Dodaj" /> </p> </form> Now i wonna save this igraci[] array in mysql, i tried like this but it doesn't work: $igraci = $_POST['igraci']; $query = "INSERT INTO klanovi (naziv, website, email, igraci) VALUES ('{$naziv}', '{$website}', '{$email}', '{$igraci}')"; $result = mysql_query($query, $connection); How can i do this? Thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/216086-save-array-from-inputs-at-mysql-as-array-separated-with-comma/ Share on other sites More sharing options...
jcbones Posted October 18, 2010 Share Posted October 18, 2010 $igraci = implode(',',$_POST['igraci']); //from array to comma separated list. $query = "INSERT INTO klanovi (naziv, website, email, igraci) VALUES ('{$naziv}', '{$website}', '{$email}', '{$igraci}')"; $result = mysql_query($query, $connection); Quote Link to comment https://forums.phpfreaks.com/topic/216086-save-array-from-inputs-at-mysql-as-array-separated-with-comma/#findComment-1123137 Share on other sites More sharing options...
UnknownPlayer Posted October 18, 2010 Author Share Posted October 18, 2010 Thanks, and how can i read them from mysql, i mean to read 1 by 1? With foreach or? Quote Link to comment https://forums.phpfreaks.com/topic/216086-save-array-from-inputs-at-mysql-as-array-separated-with-comma/#findComment-1123336 Share on other sites More sharing options...
jcbones Posted October 20, 2010 Share Posted October 20, 2010 Thanks, and how can i read them from mysql, i mean to read 1 by 1? With foreach or? Yeah, you will have to read them with a foreach. It is not advisable to save them as a comma separated list in mysql. I didn't go into all of that, but just answered your question. I have no idea what 'igraci' means, but would think that you should use a separate table to hold those values. Using a primary key linking back to the 'klanovi' table's row that those values are tied to. This lets you pull a table join to group all of those values. This would. A. Make it easier to manipulate the data. B. Make it easier to delete only one of said values. C. Further your database design in the the Normal Form. Quote Link to comment https://forums.phpfreaks.com/topic/216086-save-array-from-inputs-at-mysql-as-array-separated-with-comma/#findComment-1124178 Share on other sites More sharing options...
UnknownPlayer Posted October 20, 2010 Author Share Posted October 20, 2010 Thanks, and how can i read them from mysql, i mean to read 1 by 1? With foreach or? Yeah, you will have to read them with a foreach. It is not advisable to save them as a comma separated list in mysql. I didn't go into all of that, but just answered your question. I have no idea what 'igraci' means, but would think that you should use a separate table to hold those values. Using a primary key linking back to the 'klanovi' table's row that those values are tied to. This lets you pull a table join to group all of those values. This would. A. Make it easier to manipulate the data. B. Make it easier to delete only one of said values. C. Further your database design in the the Normal Form. I know, i go now in that way, thanks Quote Link to comment https://forums.phpfreaks.com/topic/216086-save-array-from-inputs-at-mysql-as-array-separated-with-comma/#findComment-1124610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.