With the current code, it's very inefficient, confusing and seems to lack performance.
What could I improve in the MySQL Querying, or PHP to make this code easier and less [ all over the place ].
Are there better ways to replace what I'm currently trying to accomplish, which is to retrieve information from the database [ according to the iD ] and display them. My question is mostly based towards the foreach.
Posts table
+---------------+
|Post_iD |
|message |
|uid_fk |
|tagged_people |
|_iP |
|created |
|uploads |
+---------------+
->load_messages.php -->
<?php
$lastid = "";
if ($lastid == '')
$lastid = 0;
if ( $_iD ) {
$updatesarray = $Wall->Updates($_iD, $lastid);
$total = $Wall->Total_Updates($_iD);
} else {
$updatesarray = $Wall->Friends_Updates($_iD, $lastid);
$total = $Wall->Total_Friends_Updates($_iD);
}
if ($updatesarray) {
foreach ($updatesarray as $data) {
$post_iD = $data['post_iD'];
$orimessage = $data['message'];
$message = tolink(htmlcode($data['message']));
$time = $data['created'];
$mtime = date("g:i", $time);
$_iUsername = $data['_iUsername'];
$uploads = $data['uploads'];
$msg_uid = $data['uid_fk'];
?>
<ul class="_Om" id="stbody<?php echo $post_iD;?>">
<li>
<div class="_VC">
<div class="stimg">
<img src="<?php echo $Profile_Pic;?>" class='picture' alt='<?php echo $_iUsername;?>'/>
</div>
<div class="">
<b class="timeago">
<?php echo $_iUsername;?> ·
<a href='<?php echo $base_url ?>status/<?php echo $post_iD; ?>'title='<?php echo $time;?>' class="timeposted">
<?php echo $mtime;?>
</a>
</b>
</div>
<div class="body_text">
<?php echo clear($message);?>
</div>
<?php
if ($uploads) {
echo "<div style='margin-top:10px'>";
$s = explode(",", $uploads);
foreach ($s as $a) {
$newdata = $Wall->Get_Upload_Image_Id($a);
if ($newdata)
echo "<a href='uploads/" . $newdata['image_path'] . "' rel='facebox'><img src='uploads/" . $newdata['image_path'] . "' class='imgpreview' /></a>";
}
echo "</div>";
}
?>
<div class="stexpandbox">
<div class="stexpand<?php echo $post_iD;?>">
<?php
if (textlink($orimessage)) {
$link = textlink($orimessage);
echo Expand_URL($link);
}
?>
</div>
</div>
<?php if ($_iD == $msg_uid) { ?>
<a class="stdelete" href="#" id="<?php echo $post_iD;?>" title="Delete Update"></a>
<?php } ?>
</div>
</li>
</ul>
<?php } if ($total > $perpage) { ?>
<div id="more<?php echo $post_iD;?>" class="morebox">
<a href="#" class="more" id="<?php echo $post_iD;?>">More</a>
</div>
<?php } } else echo '<h3 id="noupdates">No Updates!</h3>';?>
Database query (Updates,Total_Updates,Friends_Updates,Total_Friends_Updates)
http://pastie.org/private/j66vwnsfyk1fai7zlnrrg