Jump to content

Using variables outside the loop


livewirerules

Recommended Posts

How do i use the values withing a while loop out side the loop?

 

eg:

$sql="select *from custwhere account='".$number."'";
	$result=mysql_query($sql) or die(mysql_error());

	while ($row=mysql_fetch_array($result)) {
		$name=$row['username'];
$email=$row['email'];

	}

 

I want to use the variables $name and $email outside the loop.. Ho wdo i do it?

Link to comment
https://forums.phpfreaks.com/topic/206032-using-variables-outside-the-loop/
Share on other sites

declare the variables before the loop.

 

$email="";

$name="";

 

That's actually defining a variable.

 

Declaring a variable: simply writing a variable name to be used later ($var;).

 

Defining a variable: declaring a variable and assigning a value/initializing it in one step ($var = "value"; ).

 

Variables cannot be used unless they contain a value.

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.