Kaskus

Tech

meong_garongAvatar border
TS
meong_garong
gimana cara join 2 table berbeda php pdo
permisi suhu dan mastah sekalian emoticon-Smilie
saya seoranh nubitol dalam web design dan programing
saya mohon bantuan mastah sekalian untuk membantu ane, ane bingung gimana caranya menjoin table yg berbeda dalam php pdo

yg warna merah querynya gan
tablet yg mau di gabung users dan posts

index.php
<?php
require_once 'library/DatabaseObject.php';
require_once 'library/Db_Select.php';
require_once 'model/Post.php';
require_once 'model/Comment.php';
require_once 'inc/functions.php';
$post = new Post();
$comment = new Comment();
$limit = 10;
$records = $limit;
$show_more_button = 0;
switch($_GET['act']){
case 'add':
$post->name = checkValues($_POST['name']);
$post->post = checkValues($_POST['post']);
$post->userip = $_SERVER['REMOTE_ADDR'];
$post->date_created = strtotime(date("Y-m-d H:i:s"));
$post->save();

$select = $post->select();
$select->from('posts', array('*', 'UNIX_TIMESTAMP() - date_created AS CommentTimeSpent'));
$select->order('p_id', 'DESC');
$select->limit(0, 1);
$posts = $post->fetchObj($select);

break;

case 'more':
$show = $_POST['show'];
$records = $show + $limit;
$select = $post->select();
$select->from('posts', array('*', 'UNIX_TIMESTAMP() - date_created AS CommentTimeSpent'));
$select->order('p_id', 'DESC');
$select->limit($show, $limit);
$posts = $post->fetchObj($select);
$select = $post->select();
$select->from('posts');
$select->limit($records, $limit);
$check_result = count($post->fetchObj($select));
if($check_result > 0)
$show_more_button = 1;
break;

default:
$select = $post->select();
$select->from('posts', array('*', 'UNIX_TIMESTAMP() - date_created AS CommentTimeSpent'));
$c = $post->fetchObj($select);
$select->limit(0, $limit);
$select->order('p_id', 'DESC');
$posts = $post->fetchObj($select);
if((count($c)) > $limit)
$show_more_button = 1;
break;
}

foreach ($posts as $row): ?>
<div class="friends_area" id="record-<?php echo $row->p_id; ?>">
<img src="images/avatar-post.png" class="alignleft" alt="" />
<label class="alignleft name">
<b><?php echo ucwords($row->name);?></b>
<em><?php echo $row->post;?></em>
<br clear="all" />
<span><?php echo getTime($row->CommentTimeSpent, $row->date_created); ?></span>
<a href="[removed]void(0)">p_id ?>" class="showCommentBox">Komentar</a>
</label>
<?php
$userip = $_SERVER['REMOTE_ADDR'];
if($row->userip == $userip):?>
<a href="[removed]void(0);" class="delete">Hapus</a>
<?php endif; ?>
<br clear="all" />

<div id="CommentPosted<?php echo $row->p_id ?>">
<?php
$select_c = $comment->select();
$select_c->from('posts_comments', array('*', 'UNIX_TIMESTAMP() - date_created AS CommentTimeSpent'));
$select_c->where('p_id = ?', $row->p_id);
$select_c->order('c_id', 'ASC');
$select_c->limit(0, 10);
$comments = $comment->fetchObj($select_c);
$comment_num_row = count($comments);
if($comment_num_row):
foreach ($comments as $rowC):?>
<div class="commentPanel" id="record-<?php echo $rowC->c_id;?>" align="left">
<img src="images/avatar-comment.jpeg" width="40" class="alignleft CommentImg" alt="" />
<label class="postedComments">
<?php echo $rowC->comment;?>
<br clear="all" />
<span class="commentTime">
<?php echo getTime($rowC->CommentTimeSpent, $rowC->date_created); ?>
</span>
<?php
$userip = $_SERVER['REMOTE_ADDR'];
if($rowC->userip == $userip):?>
��<a href="#">c_id;?>" class="c_delete">Hapus</a>
<?php endif;?>
</label>
<br clear="all" />
</div>
<?php endforeach;?>
<?php
endif;?>
</div>
<div class="commentBox" align="right" id="commentBox-<?php echo $row->p_id;?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>>
<img src="images/avatar-comment.jpeg" width="40" class="alignleft CommentImg" style="display:none" alt="" />
<label id="record-<?php echo $row->p_id;?>">
<textarea class="commentMark" id="commentMark-<?php echo $row->p_id;?>" name="commentMark" cols="60"></textarea>
</label>
<br clear="all" />
<a id="SubmitComment" class="small button comment" style="display:none">Komen</a>
</div>
</div>
<?php
endforeach;

if($show_more_button == 1):?>
<div id="bottomMoreButton">
<a id="<?php echo @$records?>" class="more_records" href="[removed] void(0)">Kiriman lama</a>
</div>
<?php endif; ?>

konkoow was here emoticon-Smilie
Diubah oleh meong_garong 05-11-2013 18:58
0
1.1K
3
GuestAvatar border
Komentar yang asik ya
Urutan
Terbaru
Terlama
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan