Jump to content

Recommended Posts

Hey guys, i'm creating a facebook clone. Almost there, got the main/basic features all done, however i've got one piece of code which is really bugging me, don't worry about it being messy and horribley coded. I will be improving and optimising it every chance i get once i've got this down.

 

it's on the main page, i want it to display all recent status' that have been made, i can display them however i think i've bugg'd the SQL somewhere and it's driving my crazy, any help would be greatly appriciated :)

 

Thanks

 

  <?php
  	$sql = mysql_query("SELECT * FROM statuses ORDER BY id DESC");
    $sql = mysql_query("SELECT * FROM statuses LEFT JOIN users ON statuses.userid = users.id");
while ($row = mysql_fetch_assoc($sql)) {
$status_id = $row['id'];
$status = $row['status'];
$time_posted = $row['time_posted'];
$sql2 = mysql_query("SELECT username,avatar_url FROM users WHERE id=$userid LIMIT 1");
while ($row2=mysql_fetch_array($sql)){
$usernamestatus = $row2['username'];
$avatar_url = $row2['avatar_url'];
echo '<div id="content">';
echo "<img src='/photos/$usernamestatus/$avatar_url' height='50px' width='50px' />";
echo "<a href=\"profile.php?id=$userid\">". $usernamestatus ."</a>";
echo "<br />";
echo $status;
	echo " <span class=x><a href=delete_status.php?id=$status_id>x</a></span>";
	echo "<br />";
echo time_ago($time_posted);
echo "<br />";
echo "<br />";
echo "</div>";
	}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/246637-facebook-clone-help/
Share on other sites

You absolutely should never do SQL inside of a loop, a JOIN is almost always the correct replacement.  In fact, you've DONE your join, yet you still do unnecessary queries inside your loop.

 

print_r($row) to see what the contents are.  Maybe you're doing it wrong.  There's nothing here to indicate that your array indicies are correct.

 

If you're making a social network for the fun of it and to learn, it's a good place to start.  Lots of complex relationships in a social network.  If you're doing it to actually get traffic or make a business, stop right now. 

 

-Dan

Link to comment
https://forums.phpfreaks.com/topic/246637-facebook-clone-help/#findComment-1266492
Share on other sites

How do you propose to gain a foothold on Facebook if you're making a clone?

No one wants another Facebook. I'd stop making this clone if I were you and make something better than Facebook.

 

Unless you're just screwing around, in which case go nuts.

Link to comment
https://forums.phpfreaks.com/topic/246637-facebook-clone-help/#findComment-1266508
Share on other sites

How do you propose to gain a foothold on Facebook if you're making a clone?

No one wants another Facebook. I'd stop making this clone if I were you and make something better than Facebook.

I worked at a social network for the last couple years.  It's possible to exist alongside facebook, but you need tens of millions of dollars and at least a dozen developers, hopefully more.  Plus, advertising, compelling content, and lots and lots of luck.

 

-Dan

Link to comment
https://forums.phpfreaks.com/topic/246637-facebook-clone-help/#findComment-1266520
Share on other sites

Guys, i'm just doing this on my localhost to see if i can build anything remotely like facebook. For the fun :) and it's going pretty well :D, but yeah i know that it's all mucky and horrible. I'm not getting any errors, however it's only displaying 1status, instead of the 100's that are there. Thankyou for your help so far guys.

Link to comment
https://forums.phpfreaks.com/topic/246637-facebook-clone-help/#findComment-1266526
Share on other sites

Right this is what i've got atm,

 

  <?php
  	$sql =  mysql_query("SELECT * FROM statuses LEFT JOIN users ON statuses.userid = users.id");
while ($row = mysql_fetch_assoc($sql)) {
$status_id = $row['id'];
$status = $row['status'];
$time_posted = $row['time_posted'];
$sql2 = mysql_query("SELECT username,avatar_url FROM users WHERE id=$userid LIMIT 1");
while ($row2=mysql_fetch_array($sql2)){
$usernamestatus = $row2['username'];
$avatar_url = $row2['avatar_url'];
print_r($row);
print"<br />";
print_r($row2);
echo '<div id="content">';
echo "<img src='/photos/$usernamestatus/$avatar_url' height='50px' width='50px' />";
echo "<a href=\"profile.php?id=$userid\">". $usernamestatus ."</a>";
echo "<br />";
echo $status;
	echo " <span class=x><a href=delete_status.php?id=$status_id>x</a></span>";
	echo "<br />";
echo time_ago($time_posted);
echo "<br />";
echo "<br />";
echo "</div>";
	}
}
}
?>

 

Array ( [id] => 1 [status] => test [userid] => 1 [time_posted] => 18:42:36 [username] => ****** [password] => ****** [email] => ****  [pm_count] => 1 [avatar_url] => **** [about_me] => [interested] => Women [relationship] => In a Relationship [gender] => Male )
Array ( [0] => ****** [username] => ***** [1] => ***** [avatar_url] =>***** ) 

 

From what i can see, there is some serious bug in here.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/246637-facebook-clone-help/#findComment-1266532
Share on other sites

No worries everyone! i fixed it myself :D

 

  <?php
  	$sql =  mysql_query("SELECT * FROM statuses LEFT JOIN users ON statuses.userid = users.id");
while ($row = mysql_fetch_assoc($sql)) {
$status_id = $row['id'];
$status = $row['status'];
$time_posted = $row['time_posted'];
$userid = $row['userid'];
$sql2 = mysql_query("SELECT username,avatar_url FROM users WHERE id=$userid LIMIT 1");
while ($row2=mysql_fetch_array($sql2)){
$usernamestatus = $row2['username'];
$avatar_url = $row2['avatar_url'];
print_r($row);
print_r($row2);
echo '<div id="content">';
echo "<img src='/photos/$usernamestatus/$avatar_url' height='50px' width='50px' />";
echo "<a href=\"profile.php?id=$userid\">". $usernamestatus ."</a>";
echo "<br />";
echo $status;
	echo " <span class=x><a href=delete_status.php?id=$status_id>x</a></span>";
	echo "<br />";
echo time_ago($time_posted);
echo "<br />";
echo "<br />";
echo "</div>";
	}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/246637-facebook-clone-help/#findComment-1266536
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.