Hi all
This is my first post and I know most users hate to help with debugging but I am trying to implement a twitter system into my website as it would be the main platform. I am currently following this tutorial which is very helpful but am having trouble finishing this baby up.
http://www.ibm.com/developerworks/op...html#icomments
Right now, I have everything working properly but my code is not able to retrieve the posts back from the database. "posts" are being saved to the database but not being able to be retrieved. I feel that this has a lot to do with the function show_post(). Perhaps it has something to do with implode as well? I say this because I know that implode() has to accept an array and I realize that some of the code in the tutorial is incorrect.
Somethign important that I need to mention is that I did change some values in the file. One of them is in implode() since I know that it only accepts arrays. I changed $userid to $posts.
Also, there are no error messages. Something is just not working correctly since the immediate message I receive is that "You haven't posted anything yet!" Obviously my code is not grabbing the values from the database correctly.
Here is the function on my end.
Code:
//selects the posts from the tables and fetches the results
function show_posts($userid,$limit=0){
$posts = array();
$user_string ="'" .implode(",", $posts). "'";
$extra = " and id in ($user_string)";
if ($limit > 0){
$extra = "limit $limit";
}else{
$extra = '';
}
$sql = "select user_id, body, stamp from posts
where user_id='$user_string'
order by stamp desc $extra";
//echo $sql;
$result = mysql_query($sql);
while($data = mysql_fetch_object($result)){
$posts[] = array( 'stamp' => $data->stamp,
'user_id' => $data->user_id,
'body' => $data->body
);
}
return $posts;
}
And here is the main index\profile.php page:
Code:
<!-- Shows posts on page-->
<?php
$posts = show_posts($_SESSION['userid']);
if (count($posts)){
?>
<table border='1' cellspacing='0' cellpadding='5' width='500'>
<?php
foreach ($posts as $key => $list){
echo "<tr valign='top'>\n";
echo "<td>".$list['user_id'] ."</td>\n";
echo "<td>".$list['body'] ."<br/>\n";
echo "<small>".$list['stamp'] ."</small></td>\n";
echo "</tr>\n";
}
?>
</table>
<?php
}else{
?>
<p><b>You haven't posted anything yet!</b></p>
<?php
}
?>
Thanks so much, I really appreciate it, and I'm glad I made my first post here! Awaiting your replies!