<?php
$link=@mysql_connect("localhost","root","root") or die ("数据库链接失败".mysql_error());
mysql_select_db("test",$link);
mysql_query("set names gb2312");
$sql=mysql_query("select * from 20100907");
$row=mysql_fetch_array($sql);
foreach($row as $id=>$val){
$title=$val[0];
$content=$val[1];
$time=time();
$path=$id.".html";
$fp=fopen("news.html","r");
$str=fread($fp,filesize("news.html"));
$str=str_replace("{title}",$title,$str);
$str=str_replace("{content}",$content,$str);
fclose($fp);
$handle=fopen($path,"w");
fwrite($handle,$str);
fclose($handle);
echo "创建成功";
}/*
echo
date("Ymdhms")." ";
time();*/
?>这样写不对
请问我该如何写?
$link=@mysql_connect("localhost","root","root") or die ("数据库链接失败".mysql_error());
mysql_select_db("test",$link);
mysql_query("set names gb2312");
$sql=mysql_query("select * from 20100907");
$row=mysql_fetch_array($sql);
foreach($row as $id=>$val){
$title=$val[0];
$content=$val[1];
$time=time();
$path=$id.".html";
$fp=fopen("news.html","r");
$str=fread($fp,filesize("news.html"));
$str=str_replace("{title}",$title,$str);
$str=str_replace("{content}",$content,$str);
fclose($fp);
$handle=fopen($path,"w");
fwrite($handle,$str);
fclose($handle);
echo "创建成功";
}/*
echo
date("Ymdhms")." ";
time();*/
?>这样写不对
请问我该如何写?
id name title sex
2foreach($row as $id=>$val){
改成
while($row = mysql_fetch_array($sql)){同时循环体内的,id的值,title,name可以用 $row['id'], $row['title']等方式取值