<?php $mysql_host = 'myhost'; $mysql_user='root'; $mysql_password=''; $mysql_db='customer'; if (!$link = mysql_connect($mysql_host,$mysql_user,$mysql_password)) { echo 'Could not connect to mysql'; exit; } if (!mysql_select_db($mysql_db, $link)) { echo 'Could not select database'; exit; } $sql = "SELECT * FROM customer" $result = mysql_query($sql, $link); if (!$result) { echo "DB Error, could not query the database\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_assoc($result)) { echo $row['id']; echo "<br>"; echo $row['customer']; echo "<br>"; echo $row['addr']; echo "<br>"; } mysql_free_result($result); ?>
Hi , How can i convert $result to HTML file ( one row to one html file ) anyone suggestion me please Thank you,
I am NOT a PHP guy, but I employ one who has done something like this in the past. I believe PHP has a command to write to a file. As long as your server allows for files to be created by scripts on the server, you should be able to use it. A word of caution though - most cut rate hosting services like Godaddy for example, prohibit writing files because of the security implications. If one sloppy person on one server writes a bad script, it can compromise all of the websites on that server.
Here you go, the changes are in bold: <?php $mysql_host = 'myhost'; $mysql_user='root'; $mysql_password=''; $mysql_db='customer'; if (!$link = mysql_connect($mysql_host,$mysql_user,$mysql_password)) { echo 'Could not connect to mysql'; exit; } if (!mysql_select_db($mysql_db, $link)) { echo 'Could not select database'; exit; } $sql = "SELECT * FROM customer" $result = mysql_query($sql, $link); if (!$result) { echo "DB Error, could not query the database\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_assoc($result)) { echo $row['id']; echo "<br>"; echo $row['customer']; echo "<br>"; echo $row['addr']; echo "<br>"; [b]$text_output = "$row[id] $row[customer] $row[addr]";[/b] [b] $fp = @fopen("/path/to/file/$row[id].txt", 'w'); @fwrite($fp, $text_output); @fclose($fp); [/b] } mysql_free_result($result); ?> ?> Code (markup): -the mole