我的 content.php 中有一个 while 循环,我想像参数一样使用 $result。如何从 content.php 文件中调用函数并在我的 while 循环中使用 $result?
while ($row = mysql_fetch_array($result))
{
$ename = stripslashes($row['name']);
$eemail = stripslashes($row['email']);
$ebox = stripslashes($row['lund']);
$ecategori = stripslashes($row['LundaBlogg']);
$epost = stripslashes($row['post']);
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5(strtolower($eemail))."&size=70";
echo
(
'<li>
<div class="datum">'.$row['date'].'</div>
<div class="meta"><img src="'.$grav_url.'" alt="Gravatar" /><p>'.$ename.'</p></div>
</br>
<div class="categori"><p>Kategori: '.$ecategori.'</p></div>
<div class="topic"><p>'.$ebox.'</p></div>
<div class="shout"><p>'.$epost.'</p></div>
<div class="raderaknapp"><a href="../delete_ac.php?id=' . $row['id'] . '"class=\"icon-2 info-tooltip\">Radera Inlägg</a></div>
<div class="raportpost"><p><a href="mailto:someone@example.com?Subject=Hello%20again">Rapportera inlägg</a></p></div>
</li>'
);
?>
<h4>
<form action="<?php echo $self?>" method="POST">
<input type="hidden" name="id" value="<?php echo $row['id']?>"/>
<input type = "submit" name="Gilla" value = 'Gilla'"/>
</form>
</h4>
<div id="radera-infotwo">
<span onmouseover="ShowText('Messagetwo'); return true;" onmouseout="HideText('Messagetwo'); return true;" href="javascript:ShowText('Messagetwo')">
<img src="http://www.wallpaperama.com/forums/post-images/20081107_6718_question-mark.gif">
</span>
</div>
<div id="radera-info">
<span onmouseover="ShowText('Message'); return true;" onmouseout="HideText('Message'); return true;" href="javascript:ShowText('Message')">
<img src="http://www.wallpaperama.com/forums/post-images/20081107_6718_question-mark.gif">
</span>
</div>
<?
?>
<?
echo ("Antal Gilla: " .$row['likes']);
if(isset($_POST['Gilla']) && $_POST['id'] == $row['id']){echo '<h5><img src="../images/tummen-upp.png"/>Du har Gillat detta inlägg.</h5>';}
echo "<hr>";
}
这是我的 functions.php 文件,其中有我的函数 blogPosts_get()
function blogPosts_get(){
$query = "SELECT * FROM shouts ORDER BY `id` DESC LIMIT 8;";
$result = mysql_query($query) or die('<p class="error">Wrong.</p>');
}
我已经尝试在我的函数 blogPosts_get() 中返回,但我不明白它是如何工作的。有人可以帮我从我的函数 blogPosts_get() 中获取 $result 变量,以便我可以在我的 while 循环中使用它吗?