Jump to content

[SOLVED] Concatenating WHILE iterations into a variable..


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.

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.