你好,我写功能代码
我想把包含表html的功能代码保存到mysql数据库中
function writeMsg(){
$result = mysql_query('SELECT * FROM `wp_farsc`');
if($result && mysql_num_rows ($result)> 0){
echo '<table border="2px" cellspacing="5px" width="100%">'.PHP_EOL;
echo '<tr bgcolor="yellow"><th>سکه</th><th>قیمت انلاین</th><th>تغییر قیمت</th><th>کمترین</th><th>بیشترین</th><th>زمان بروز رسانی</th></tr>'.PHP_EOL;
while($row = mysql_fetch_assoc($result)){
echo'<tr>';
echo '<td>'.$row ['titile'].'</td>';
echo '<td>'.$row ['liveprice'].'</td>';
echo '<td>'.$row ['changing'].'</td>';
echo '<td>'.$row ['lowest'].'</td>';
echo '<td>'.$row ['topest'].'</td>';
echo '<td>'.$row ['time'].'</td>';
echo'</tr>'.PHP_EOL;
}
}
mysql_close();
}
然后我将函数writeMsg卷积到可变
$oiobz1 = writeMsg(1, 'center', '', 1);
然后保存到数据库
@mysql_connect("localhost","root","") or die('connection error');
mysql_select_db('gas') or die('Can not connect to the database');
@ mysql_query("set names utf8");
$title ="today list";
$content =" writemsg()";
$statuse="Publish";
$pingo="open";
$commento="open";
$typee="post";
$auther="1";
$sql = "INSERT INTO `wp_posts`( post_author,post_title,post_content,post_status,post_type,ping_status,comment_status) VALUES('$auther','$title','". $oiobz1."','$statuse','$typee','$pingo','$commento')";
@ mysql_query($sql);
将数据保存到数据库后,除了post_content之外,所有字段都将存储。。post_content为null。。
https://i.stack.imgur.com/YgGX7.jpg
必须使用函数return;尝试使用代码
function writeMsg(){
$result = mysql_query('SELECT * FROM `wp_farsc`');
if($result && mysql_num_rows ($result)> 0){
echo '<table border="2px" cellspacing="5px" width="100%">'.PHP_EOL;
echo '<tr bgcolor="yellow"><th>سکه</th><th>قیمت انلاین</th><th>تغییر قیمت</th><th>کمترین</th><th>بیشترین</th><th>زمان بروز رسانی</th></tr>'.PHP_EOL;
$data = null;
while($row = mysql_fetch_assoc($result)){
$data .='<tr>';
$data .= '<td>'.$row ['titile'].'</td>';
$data .='<td>'.$row ['liveprice'].'</td>';
$data .='<td>'.$row ['changing'].'</td>';
$data .= '<td>'.$row ['lowest'].'</td>';
$data .= '<td>'.$row ['topest'].'</td>';
$data .= '<td>'.$row ['time'].'</td>';
$data .='</tr>'.PHP_EOL;
}
}
mysql_close();
return $data;
}