MySQL query inside php variable

I am trying to insert this HTML code inside php variable in way that build some file with fopen function. The script produces the file however the generated content is not correct . The variable is this :


<?php
$content='
<html><head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body> <font face="Arial,Verdana,sans-serif" color="#ff00ff" size="4"><a href="">Web</a> 
 <a href="">Immagini</a><a href="">Maps</a> 
 <a href="">News</a> <a href="">Video</a> 
 <a href="">Meteo</a><font face="Arial,Verdana,sans-serif" color="#ff0000" size="4">
<center><?php  while ($row= mysql_fetch_row($result1)) { echo $row[0]; ?></center> <br />
<strong>Reserve Hotel </strong></font><br />
<table> <tr> <td> <div id="rentacar"> Rent a Car</div> <br /> 
<div id="rentacamper"> Rent a Camper </div></td>
<td> <div id="booking">
<td><div id="booking"><iframe src=<?php $row[1]; } ?> id="booking-engine" name="booking-engine" width="450" height="250" frameborder="1" scrolling="Auto"></iframe></div></td></tr></table><hr>  
<script type="text/javascript" src="http://www.easyvols.org/formulaire/it/type_a/728x90_mev.js"></script>
<script type="text/javascript">setClient("55");</script>
<script type="text/javascript">setActions("clients-noh-it");</script>
<script type="text/javascript">setTargetForm("_blank");</script>
</body></html>';

and the rest of function is that :


  while ($row = mysql_fetch_row($result2)) {
 
  printf("http://www.%s.php<br />", $row[0]);  
  $handle = fopen($row[0].'.php',"w+");  
  fwrite($handle, $content);   
 }
 ?>

This is one of the php files generated :
http://trekhotel.com/bina/lowcostchina.com%20.php

thanks.

Not entirely sure what you are trying to accomplish. I use PDO for database access. Don’t understand why you have those mysql_result calls.


$sql1 = "SELECT id,dominio,URL FROM domains ORDER BY id DESC LIMIT   0,4"; 
$result1= mysql_query($sql1); 
$row = mysql_fetch_array($result1,MYSQL_ASSOC);
echo "{$row['id']} {$row['domino']} {$row['URL']}\
";

Thank you very much for reply ! the contents are writing fine in the files however i could not fix the loop to get each one page with the your defined fields , “dominio” and “URL” .


<?php 
 $sql1 = "SELECT id,dominio,URL FROM domains ORDER BY id DESC LIMIT   0,4";    
  $result1= mysql_query($sql1);    
  if(mysql_num_rows($result1)==0){
     echo " NOT FOUND!";
     exit;
}
 
  mysql_result($result1,1,"dominio"); 
 mysql_result($result1,2,"URL"); 

 while ($row =mysql_fetch_array($result1))
   {   
     echo "<center>www.$row[1]</center><br />"; 
 ?>       
  ............................
  <iframe src="<?php echo $row[2]; } ?>" id="booking-engine" name="booking-engine" width="400" 
   height="600" frameborder="1" scrolling="Auto"></iframe>
 
  

Therefore they are showing the same content in all files, please check this links :
http://trekhotel.com/bina/homepages/lowcostaustralia.com.php
http://trekhotel.com/bina/homepages/lowcostbangkok.com .php
http://trekhotel.com/bina/homepages/lowcostchina.com.php
http://trekhotel.com/bina/homepages/lastsecondalps.com.php

thanks.

You can’t execute php code inside of an assignment, at least not very easily.

Take a look at the output buffering stuff:
http://ca3.php.net/manual/en/function.ob-start.php

You basically want to capture the output of a part of your script and then write it to a file.


<?php ob_start(); ?>
<html>
blah blah blah
<center><?php echo your result1 query stuff ?>
</html>
<?php 
  $content = ob_get_clean();
  // Do your fwrite loop
?>