shortysbest Posted July 27, 2010 Share Posted July 27, 2010 I am trying to insert a string of data into my database but it is only inserting the first number, however when i print it out it echos out all of the correct information my code: $new_comment_notification = mysql_query("SELECT * FROM comments WHERE ob_id='$ob_id' AND from_id!='".$_SESSION['id']."' GROUP BY from_id "); while($notify = mysql_fetch_array($new_comment_notification)) { $idis = $notify['from_id'].", "; $ids = $idis; $quer = mysql_query("INSERT INTO comments VALUES('','$ob_id','$session','$ids', '$comment', '$date')") or die('There was an error connecting to the database at this time.'); print $ids; } it should make a string of data in the database that looks like thiS: 1, 2, 3, 18, 29, 30, etc. however all it is doing now in the database is inserting: 1 and where im printing it it prints out: 1, 2 , 3, 18, 29, 30, etc. Quote Link to comment Share on other sites More sharing options...
shortysbest Posted July 28, 2010 Author Share Posted July 28, 2010 I have data i want to put into a single row in a single column in a database, the data would look like: 1, 2, 3, 4, 5, 20, 39, 123, etc. But right now it inserts it into a new row in the database instead of a single string. my code is: $new_comment_notification = mysql_query("SELECT * FROM comments WHERE ob_id='$ob_id' AND from_id!='".$_SESSION['id']."' GROUP BY from_id "); while($notify = mysql_fetch_array($new_comment_notification)) { $ids = $notify['from_id'].', '; $quer = mysql_query("INSERT INTO comments VALUES('','$ob_id','$session','$ids', '$comment', '$date')") or die('There was an error connecting to the database at this time.'); } Quote Link to comment Share on other sites More sharing options...
trq Posted July 28, 2010 Share Posted July 28, 2010 $new_comment_notification = mysql_query("SELECT * FROM comments WHERE ob_id='$ob_id' AND from_id!='".$_SESSION['id']."' GROUP BY from_id "); $ids = array(); while($notify = mysql_fetch_array($new_comment_notification)) { $ids[] = $notify['from_id']; } $ids_string = implode(' ', $ids); $quer = mysql_query("INSERT INTO comments VALUES('','$ob_id','$session','$ids_string', '$comment', '$date')") or die('There was an error connecting to the database at this time.'); Quote Link to comment 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.