export data from a while loop

Ask about a PHP problem here.
Post Reply
chris122380
Posts: 9
Joined: Thu Jul 26, 2012 3:17 pm
Contact:

export data from a while loop

Post 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;

?>
Local Server: XAMMP 1.8.0, Windows 7 64bit
Local PHP: 5.4.4
Local Apache: 2.4.2
Local MySQL: 14.14 Distrib 5.5.25a, for Win32 (x86)
PHP/HTML Editor: Komodo Edit, version 7.1.0
chris122380
Posts: 9
Joined: Thu Jul 26, 2012 3:17 pm
Contact:

Re: export data from a while loop

Post 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>
Local Server: XAMMP 1.8.0, Windows 7 64bit
Local PHP: 5.4.4
Local Apache: 2.4.2
Local MySQL: 14.14 Distrib 5.5.25a, for Win32 (x86)
PHP/HTML Editor: Komodo Edit, version 7.1.0
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: export data from a while loop

Post by jacek »

Gotta love self-solving topics :P
Image
Post Reply