Page 1 of 1

export data from a while loop

Posted: Thu Jul 26, 2012 8:54 pm
by chris122380
I have a database that I use a loop to assign variables to it's fields. The loop then exports the data into a variable that also loops to make a list. Is there a way to have the echo do the same thing outside the loop as it does in the loop? This way the list and variables still exist after the loop dies. This might help from killing my links once this page is opened in a iframe (Please see PHP hyperlinks in a iFrame passing to a iFrame in index.php).
WHILE ($rows = mysql_fetch_array($query)): //Fetch data from $query as long as there is data to fetch

$rows = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $rows);

		// assign fields from the query to Variables using session variables
		$_SESSION['first_name'] = $rows['first_name'];
		$_SESSION['Last_name'] = $rows['last_name'];
		$_SESSION['company'] = $rows['company'];
		$_SESSION['spec'] = $rows['spec'];
		$_SESSION['discription'] = $rows['discription'];
		
$_SESSION['spec'] = str_replace (" ", "", $_SESSION['spec']);
//Deletes spaces from spec

echo '<a href="spec/',$_SESSION['spec'],'.pdf">', $_SESSION['spec'],' ',$_SESSION['discription'],'</a><br/>'; 
//Prints data into a list 

	
	endwhile;

?>

Re: export data from a while loop

Posted: Thu Jul 26, 2012 9:38 pm
by chris122380
Problem solved.
<body>
<a href="spec/<?php echo $_SESSION['spec']; ?>.pdf" target="pdf"> <?php echo $_SESSION['spec'],' ',$_SESSION['discription'], '<br />'; ?>   </a>
<?php endwhile; ?>
</body>

Re: export data from a while loop

Posted: Sun Jul 29, 2012 1:48 am
by jacek
Gotta love self-solving topics :P