Jump to content

How to insert string of data into database?


shortysbest

Recommended Posts

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.

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.');
}

$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.');

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.