wright67uk Posted June 16, 2011 Share Posted June 16, 2011 Im trying to place the corresponding name, telephone, and email address of my query from header.php into gmap.php. I pressume that I need to post the variables into; <a href='/gmap.php?postcode=" . urlencode($row['postcode']) . "'> (header.php) and then GET them in gmap.php How can I pull name, telephone and email from the query in header.php and turn them into variables? gmap.php <div id="listhold"> <?php $postcode = $_GET["postcode"]; $zoom = 15; echo "<img src='http://maps.google.com/maps/api/staticmap?zoom=$zoom&size=400x400&markers=color:blue|label:EXAMPLE|$postcode&sensor=false' class='default'/>"; ?> </div> <div id="boxright"> <!--id like to echo name, telephone, email here--> </div> header.php <?php $subtype = $_GET['subtype']; $subtype = ucwords (strtolower($subtype)); echo "<h1>$subtype</h1>"; $query = "SELECT name, phone, email, WebAddress, postcode FROM business WHERE subtype ='$subtype' AND confirmed ='Yes' ORDER BY name"; if( $result = mysql_query($query) ) { echo mysql_error(); while($row = mysql_fetch_assoc($result) ) { foreach( $row as $k => $v ) { if( empty($v) ) { unset($row[$k]); } } if( !empty($row['postcode']) ) { $row['postcode_link'] = "<p class=link><a href='/gmap.php?postcode=" . urlencode($row['postcode']) . "'>Map</a></p><br>"; } echo implode( '<br>', $row); } } ?> b.php <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Cars and Travel' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . ucwords(strtolower (($nt[$i]))) . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> <h1>Legal</h1> <?php $nt = array(); $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Legal' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . ucwords(strtolower (($nt[$i]))) . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> Link to comment https://forums.phpfreaks.com/topic/239595-geting-variables-from-a-query-within-a-foreach-statement/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.