Jump to content

[SOLVED] Concatenating WHILE iterations into a variable..


woolyg

Recommended Posts

Hi all,

 

Apart from this topic title sounding marvellously intelligent, I'm looking to see if this can be done. Here's what I'm trying to do:

 

Users upload videos to my site.

I'm trying to grab a list of their active videos, and list the video details in an email to them, as a kind of update.

 

Code:

 

<?php

$user_id = '1'; // Define the user_id

//Find out if they have any active adverts
		$get_users_active_adverts = "
		SELECT 
		*
		FROM 
		videos
		WHERE 
		videos.user_id='$user_id'	
					";
		$run_users_active_adverts = mysql_query($get_users_active_adverts);
		$num_users_active_adverts = mysql_num_rows($run_users_active_adverts);

		//If they have one or more adverts, send them an email with their stats

		if($num_users_active_adverts > = '1'){ // IF 71

				while($display_users_active_adverts = mysql_fetch_assoc($run_users_active_adverts)){ // IF 73

					$video_id = $display_users_active_adverts['video_id'];
					$video_name = $display_users_active_adverts['video_name'];

					echo "$video_name<br />"; // ******

				} // IF 73








		} else { // IF 71

		//They have no active adverts - Send them an email prompting for them to use the service.

		} // IF 71
?>

 

 

If I echo'd the results, as above, I'd get a list of video names, as per:

 

echo "$video_name<br />"; 

 

..but what I'd like to do is put all of the iterations of $video_name<br /> into a variable, that I could then place into an HTML email and send to the user.

 

If you can follow my idea, can anyone help?

 

All input appreciated.

WoolyG

 

 

 

Declare an empty variable (to be safe) before the loop

$email_body="";

 

Then inside the loop append the video details onto the variable:

$email_body.="Video $video_name\n";

 

Then at the end you'll have a long list of everything that went through the while() loop.

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.