保存在MySQL数据库功能
问题描述:
你好我写的函数代码保存在MySQL数据库功能
我想保存的功能代码巫包含到MySQL数据库表HTML
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();
}
,然后我convoert功能writeMsg到varible
$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);
后数据保存到dabase,所有字段从POST_CONTENT .. POST_CONTENT分开存放是空..
http://i.stack.imgur.com/YgGX7.jpg
答
必须使用函数返回; 尝试使用代码
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;
}
你做得不对;从不在DB中保存一个函数,只保存数据。 只需在需要时调用即可。我们需要更多关于你想要帮助你的信息。 – Loenix 2015-02-06 08:12:39