<?php
function getpostsby ($username, $limit=30) {
if (strlen($username) < 1)
return false;
$sql = '
SELECT
*
FROM
c_posts
WHERE
username = "'.mysql_real_escape_string($username).'"
LIMIT
'.$limit.'
';
$query = mysql_query($sql);
if (!$query)
return array('Error: '.mysql_error());
if(mysql_num_rows($query) == 0)
return false;
$posts = array();
while($row = mysql_fetch_array($query)) {
$posts[] = $row;
}
return $posts;
}
$posts = getpostsby('Bob');
?>
Here are some posts:
<?php
foreach ($posts as $post) {
print '<h2>'.$post['title'].'</h2>';
print '<p>'.$post['body'].'</p>';
}
?>