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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
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.