สอบถามการดึงข้อมูลหรือโพสต์ที่มีการตั้งค่า privacy

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามการดึงข้อมูลหรือโพสต์ที่มีการตั้งค่า privacy

สอบถามการดึงข้อมูลหรือโพสต์ที่มีการตั้งค่า privacy

	
จากโค้ดเป็นการดึงโพสต์ทั้งหมดของผู้ใช้มาเเสดง โดยที่ไม่ได้กำหนด topic_privacy ถ้าต้องการจะกำหนด topic_privacy เข้าไปด้วยไม่ทราบต้องเพิ่มเติมอย่างไรบ้างค่ะ 
โดยที่ topic_privacy=0 เเสดงโพสต์ให้เห็นทั้งเพื่อนผู้ใช้เเละผู้ใช้
     topic_privacy=1 เเสดงให้เห็นฉพาะผู้ใช้(เฉพาะฉัน)
<div id="profile_contain"> <?php $strSQLmember = "SELECT * FROM member WHERE member_id = '$member_id'"; $resultmember = mysql_query($strSQLmember)or die(mysql_error().$strSQLmember); $rowmember=mysql_fetch_array($resultmember); //echo $rowmember['member_name']; $strSQL = "SELECT * FROM topic WHERE member_id = '$member_id'"; $result = mysql_query($strSQL)or die(mysql_error().$strSQL); $Num_Rows = mysql_num_rows($result); $Per_Page = 10; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by topic_id DESC LIMIT $Page_Start , $Per_Page "; $result = mysql_query($strSQL); while ($row=mysql_fetch_array($result)){ $topic_id = $row['topic_id']; //echo $row['topic_name']; ?> <div class="profile_wall"> <div class="pic_profile"> <?php if($rowmember['member_pic'] == ''){?> <img src="images/bgprofile1.jpg" width="50" height="50" /> <?php }else{?> <img src="myfile/<?php echo $rowmember["member_pic"];?>" width="50" height="50" /> <?php } ?> </div> <div class="text_profile"> <span> <?php echo $rowmember['member_name']?></span> <span><?php echo $row['topic_date']; ?></span> <span style="float:right"><form id="form1" name="form1" method="post" action="profile_wall_del_confirm.php?idMem=<?php echo $topic_id;?>"> <input name="txttopic_id" type="hidden" value="<?php echo $topic_id; ?>" /> <input type="submit" name="Submit" id="button" value="ลบโพสต์" class="btn btn-default"/> </form></span> </div> <div class="text_profile2"> <!--<a href="news_feed_comment.php?topic_id=<?php echo $row["topic_id"];?>" style="text-decoration:none" >&nbsp;&nbsp;--> <?php echo $row['topic_name']; ?> </a> </br> <span style="float:right"><input type="button" name="button" id="button" value="อ่านรายละเอียดโพสต์" onclick="window.location='news_feed_comment.php?topic_id=<?php echo $row["topic_id"];?>'" class="btn btn-default"/> </span> </div> </div> <!--<div align="right"> <form id="form1" name="form1" method="post" action="well_del_confirm.php?idMem=<?php echo $topic_id;?>"> <input name="txttopic_id" type="hidden" value="<?php echo $topic_id; ?>" /> <input type="submit" name="Submit" id="button" value="ลบโพสต์" /> </form> </div>--> <div> </div> <?php } ?> </div> <div> ทั้งหมด <?= $Num_Rows;?> โพสต์หน้า :&nbsp; <!--: หน้าที่ --> <? //$Num_Pages; ?> <? if($Prev_Page) { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< ก่อนหน้า</a> "; } for($i=1; $i<=$Num_Pages; $i++){ $Page1 = $Page-2; $Page2 = $Page+2; if($i != $Page && $i >= $Page1 && $i <= $Page2) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]"; } elseif($i==$Page) { echo "<b> $i </b>"; } } if($Page!=$Num_Pages) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>ถัดไป >></a> "; } ?> </div>


Nathakarn 180.183.98.xxx 24-11-2014 19:44:16

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
<div id="profile_contain">

<?php 
			  
			  $strSQLmember = "SELECT * FROM member WHERE member_id = '$member_id'";
			  $resultmember = mysql_query($strSQLmember)or die(mysql_error().$strSQLmember);
			  $rowmember=mysql_fetch_array($resultmember);
			  //echo $rowmember['member_name'];
			  $strSQL = "SELECT * FROM topic WHERE member_id = '$member_id'";
			  $result = mysql_query($strSQL)or die(mysql_error().$strSQL);
			  
				$Num_Rows = mysql_num_rows($result);
				
				$Per_Page = 10;   // Per Page
				
				$Page = $_GET["Page"];
				if(!$_GET["Page"])
				{
					$Page=1;
				}
				
				$Prev_Page = $Page-1;
				$Next_Page = $Page+1;
				
				$Page_Start = (($Per_Page*$Page)-$Per_Page);
				if($Num_Rows<=$Per_Page)
				{
					$Num_Pages =1;
				}
				else if(($Num_Rows % $Per_Page)==0)
				{
					$Num_Pages =($Num_Rows/$Per_Page) ;
				}
				else
				{
					$Num_Pages =($Num_Rows/$Per_Page)+1;
					$Num_Pages = (int)$Num_Pages;
				}
				
				$strSQL .=" order by topic_id DESC LIMIT $Page_Start , $Per_Page ";
				$result  = mysql_query($strSQL);
	  
			  while ($row=mysql_fetch_array($result)){
			  $topic_id = $row['topic_id'];
			  //echo $row['topic_name'];			  

			  ?>
              
            
<div class="profile_wall">
<div class="pic_profile">
<?php if($rowmember['member_pic'] == ''){?>
                    <img src="images/bgprofile1.jpg" width="50" height="50" />
                    <?php }else{?>
                    <img src="myfile/<?php echo $rowmember["member_pic"];?>" width="50" height="50" />
                   <?php } ?>


</div>

<div class="text_profile">
<span> <?php echo $rowmember['member_name']?></span>                    
<span><?php echo $row['topic_date']; ?></span>
<span style="float:right"><form id="form1" name="form1" method="post" action="profile_wall_del_confirm.php?idMem=<?php echo $topic_id;?>">
                         <input name="txttopic_id" type="hidden" value="<?php echo $topic_id; ?>" />
                         <input type="submit" name="Submit" id="button" value="ลบโพสต์" class="btn btn-default"/>
                         </form></span>

</div>
<div class="text_profile2">
<!--<a href="news_feed_comment.php?topic_id=<?php echo $row["topic_id"];?>" style="text-decoration:none" >&nbsp;&nbsp;-->
                      <?php  echo $row['topic_name']; ?>
                      </a> </br>
<span style="float:right"><input type="button" name="button" id="button" value="อ่านรายละเอียดโพสต์" onclick="window.location='news_feed_comment.php?topic_id=<?php echo $row["topic_id"];?>'" class="btn btn-default"/> </span>
</div>
</div>

<!--<div align="right">
                       <form id="form1" name="form1" method="post" action="well_del_confirm.php?idMem=<?php echo $topic_id;?>">
                         <input name="txttopic_id" type="hidden" value="<?php echo $topic_id; ?>" />
                         <input type="submit" name="Submit" id="button" value="ลบโพสต์" />
                         </form>
</div>-->   

<div>

</div>                       

<?php			  
			  }
			  ?>
			       
</div>
<div>
ทั้งหมด
<?= $Num_Rows;?>
โพสต์หน้า :&nbsp;
              
              <!--: หน้าที่ -->
			  <?
			  //$Num_Pages;
			  ?> 
              <?
              if($Prev_Page)
              {
                  echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< ก่อนหน้า</a> ";
              }
              
              for($i=1; $i<=$Num_Pages; $i++){
                  $Page1 = $Page-2;
                  $Page2 = $Page+2;
                  if($i != $Page && $i >= $Page1 && $i <= $Page2)
                  {
                      echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
                  }
                  elseif($i==$Page)
                  {
                      echo "<b> $i </b>";
                  }
                                              }
              if($Page!=$Num_Pages)
              {
                  echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>ถัดไป >></a> ";
              }
			?>
</div>

จากโค้ดเป็นการดึงโพสต์ทั้งหมดของผู้ใช้มาเเสดง โดยที่ไม่ได้กำหนด topic_privacy ถ้าต้องการจะกำหนด topic_privacy เข้าไปด้วยไม่ทราบต้องเพิ่มเติมอย่างไรบ้างค่ะ 
โดยที่ topic_privacy=0 เเสดงโพสต์ให้เห็นทั้งเพื่อนผู้ใช้เเละผู้ใช้
     topic_privacy=1 เเสดงให้เห็นฉพาะผู้ใช้(เฉพาะฉัน)



ตาราง member
friend_1=member_id  ผู้ใช้

member_id member_name
                 27 Mooo                   
                 28 NOO                    
                 29 Sooo                    

ตาราง friend
friend_1 ผูใช้  friend_2 เพื่อนผู้ใช้

friend_id friend_1 friend_2
47             28            27           
48             27            28           
39             27            29           

ตาราง topic
topic_privacy=0 เเสดงโพสต์ให้เห็นทั้งเพื่อนผู้ใช้เเละผู้ใช้
topic_privacy=1 เเสดงให้เห็นฉพาะผู้ใช้(เฉพาะฉัน)
 
topic_id topic_name topic_detail   topic_privacy   member_id topic_date                  
117         test1               test1                           0                    27             03-10-2557 09:37:29
21           nach3             nach3                   1                           28                 03-10-2557 10:13:33
 

 

 



nathakarn 180.183.102.xxx 24-11-2014 19:48
 ความคิดเห็นที่ 2
ใส่เงื่อนไขเข้าไปธรรมดาเลยมั้ย ไม่ค่อยเข้าใจคำถาม
 
 
SELECT * FROM topic WHERE topic_privacy=0 AND member_id = '$member_id'


ninenik 1.47.211.xxx 25-11-2014
 ความคิดเห็นที่ 3
<div id='newsfeed_contain'>
<div class='block_news_add_new'>

<form id="form2" name="form2" method="post" enctype="multipart/form-data" action="add_topic.php" onsubmit="return fncSubmit();">

<div class="panel panel-default">
  <div class="panel-body" >

  <table width='650px' >
<tr>
<td valign='top' width="160px"><label for="exampleInputPassword1">ชื่อโพสต์:</label></td>
<td valign='top'>
                    <input name="txttopic_name" type="text" id="textfield" value=""  class="form-control" placeholder="พิมพ์ชื่อโพสต์" />
                  </td>
</tr>
</table>
</div>

  <div class="panel-body">
  <table width='650px' >
  <tr>
<td valign='top' width="160px" ><label for="exampleInputPassword1">รายละเอียดโพสต์:</label></td>
<td valign='top'>
                    <textarea name="txttopic_detail" cols="70" rows="10" id="txttopic_detail" class="form-control" placeholder="พิมพ์รายละเอียดโพสต์"   ></textarea>
                  </td>
</tr>
  </table>
  </div>
  
  <div class="panel-body">
  <table width='650px' >
  <tr>
<td valign='top' width="160px" ><label for="exampleInputPassword1">รูปภาพ/วิดีโอ:</label></td>
<td valign='top'>เเนบไฟล์หรือรูปภาพ &nbsp;</br> <input type="file" name="QPic" OnChange="showPreview(this)"  on />

</td>
</tr>
  </table>
  </div>

  <div class="panel-body-new">
  <table width='650px' >
  <tr>
  <td valign='top' width="160px"><label for="exampleInputPassword1">ตั้งค่าความเป็นส่วนตัว:</label></td>
  <td valign='top'><ul class="list-group">
  <li class="list-group-item"><input type="radio" name="topic_privacy" id="topic_privacy0"  value="0">&nbsp;เฉพาะเพื่อน</li>
  <li class="list-group-item"><input type="radio" name="topic_privacy" id="topic_privacy1"  value="1">&nbsp;เฉพาะฉัน</li>
</ul>
  </td>
  </tr>
  </table>
  </div>
  
  <div class="panel-body">
  <table width='650px' >
  <tr>
<td colspan="2" valign='top'> <input name="Submit" type="submit" class="btn btn-default" id="Submit" value="   โพสต์   " /> 
<input name="Cancel" type="button" value="ยกเลิกการโพสต์" onClick="window.location='profile_wall.php'" class="btn btn-default"/ > 
</td>
</tr>
</table>
  </div>
  
</div>

    </form>
           
</div>

</div>

เพิ่มข่าวใหม่
เเนบไฟล์หรือรูปภาพ  
  •  เฉพาะเพื่อน
  •  เฉพาะฉัน
 
topic_id topic_name topic_detail   topic_privacy   member_id topic_date                  
117         test1               test1                           0                    27             03-10-2557 09:37:29
21           nach3             nach3                   1                           28                 03-10-2557 10:13:33
 

ข้อมูลที่บันทึกลงเป็นรุปเเบบดังข้างบนค่ะ

โดยที่ topic_privacy=0 เฉพาะเพื่อน   ต้องการให้ทุกคนที่เป็นเพื่อน (friend_2 จาตาราง friend)
                                    เเละผู้โพสต์(member_id=friend_1)มองเห็นโพสต์ได้
         topic_privacy=1 เฉพาะฉัน       มองเห็นเฉพาะผู้โพสต์ 


ต้องการทราบว่าตอนที่ดึงข้อมูลมาเเสดงไม่ทราบว่าต้องทำอย่างไร ถึงจะเป็นไปตาม topic_privacy ที่ตั้งไว้ค่ะ
ไม่ทราบว่าพอจะเข้าใจรึป่าวค่ะ  ^^ 



nathakarn 180.183.98.xxx 26-11-2014 12:46
 ความคิดเห็นที่ 4
ถ้า โพสนั้นเป็นของผู้ใช้ merber_id=$member_id สมมติเท่ากับ 27
ไม่ว่า topic_privacy=0 หรือ topic_privacy=1 ผู้ใช้จะเห็นโพสของตัวเองทั้งหมดหรือไม่
 
ถ้า โพสนั้นเป็นของคนอื่น  merber_id ไม่ใช่ 27 เช่นเป็นของ 28
แต่ topic_privacy=0 และ 27 เป็นเพื่อนของ 28 จะแสดงด้วยหรือไม่
 
ถ้าใช่ทั้งสองกรณีด้านบน
คำสั่งด้านล่าง คือแนวทาง

SELECT a. * , b. * , c. *   
FROM topic a  
LEFT JOIN (  
member b, friend c  
)   
ON a.member_id = b.member_id  
AND a.member_id=c.friend_1
WHERE 
( a.member_id = '27' )
OR
( a.topic_privacy=0 AND c.friend_2='27') 
GROUP BY a.topic_id


ninenik 58.11.138.xxx 26-11-2014
 ความคิดเห็นที่ 5
ใช่ทั้งสองกรณีค่ะ เเต่พอเราเลือก เฉพาะฉัน (topic_privacy=1) ซึ่งผู้ใช้ต้องการเห็นคนเดียว ได้ผลลัพธ์เหมือนกับ topic_privacy=0 
คือตั้งเฉพาะฉันเฉพาะผู้ใช้คนเดียว เเต่เพื่อนก็ยังมองเห็นของเราค่ะ

 
  •  เฉพาะเพื่อน
  •  เฉพาะฉัน


<!--css style-->
<?php include_once 'js.php';?>
<?php 
			  
			  $strSQLmember = "SELECT * FROM member WHERE member_id = '$member_id'";
			  $resultmember = mysql_query($strSQLmember)or die(mysql_error().$strSQLmember);
			  $rowmember=mysql_fetch_array($resultmember);
?>	

<div class="head_on_page_right"><h4>โพสต์ ทั้งหมดของคุณ&nbsp;<font color="#009EE3"><? echo $rowmember['member_name'] ?></font></h4>
</div>
<div id="profile_contain">

<?php 
			  
			  $strSQLmember = "SELECT * FROM member WHERE member_id = '$member_id'";
			  $resultmember = mysql_query($strSQLmember)or die(mysql_error().$strSQLmember);
			  $rowmember=mysql_fetch_array($resultmember);
			  //echo $rowmember['member_name'];
			  $strSQL = "SELECT a. * , b. * , c. *     
FROM topic a    
LEFT JOIN (    
member b, friend c    
)     
ON a.member_id = b.member_id    
AND a.member_id=c.friend_1  
WHERE   
( a.member_id = '$member_id' )  
OR  
( a.topic_privacy=0 AND c.friend_2='$member_id')   
GROUP BY a.topic_id ";
			  $result = mysql_query($strSQL)or die(mysql_error().$strSQL);
			  
				$Num_Rows = mysql_num_rows($result);
				
				$Per_Page = 10;   // Per Page
				
				$Page = $_GET["Page"];
				if(!$_GET["Page"])
				{
					$Page=1;
				}
				
				$Prev_Page = $Page-1;
				$Next_Page = $Page+1;
				
				$Page_Start = (($Per_Page*$Page)-$Per_Page);
				if($Num_Rows<=$Per_Page)
				{
					$Num_Pages =1;
				}
				else if(($Num_Rows % $Per_Page)==0)
				{
					$Num_Pages =($Num_Rows/$Per_Page) ;
				}
				else
				{
					$Num_Pages =($Num_Rows/$Per_Page)+1;
					$Num_Pages = (int)$Num_Pages;
				}
				
				$strSQL .=" order by a.topic_id DESC LIMIT $Page_Start , $Per_Page ";
				$result  = mysql_query($strSQL);
	  
			  while ($row=mysql_fetch_array($result)){
			  $topic_id = $row['a.topic_id'];
			  //echo $row['topic_name'];			  

			  ?>
              

           
<div class="profile_wall">
<div class="pic_profile">
<?php if($rowmember['member_pic'] == ''){?>
                    <img src="images/bgprofile1.jpg" width="50" height="50" />
                    <?php }else{?>
                    <img src="myfile/<?php echo $rowmember["member_pic"];?>" width="50" height="50" />
                   <?php } ?>


</div>

<div class="text_profile">
<span><label> <?php echo $rowmember['member_name']?></label></span>&nbsp;&nbsp;&nbsp;                    
<span><?php echo $row['topic_date']; ?></span>
<span style="float:right"><form id="form1" name="form1" method="post" action="profile_wall_del_confirm.php?idMem=<?php echo $topic_id;?>">
                         <input name="txttopic_id" type="hidden" value="<?php echo $topic_id; ?>" />
                         <input type="submit" name="Submit" id="button" value="ลบโพสต์" class="btn btn-default"/>
                         </form></span>

</div>
<div class="text_profile2">
<!--<a href="news_feed_comment.php?topic_id=<?php echo $row["topic_id"];?>" style="text-decoration:none" >&nbsp;&nbsp;-->
                      <?php  echo $row['topic_name']; ?>
                      </a> </br>
<span style="float:right"><input type="button" name="button" id="button" value="อ่านรายละเอียดโพสต์" onclick="window.location='news_feed_comment.php?topic_id=<?php echo $row["topic_id"];?>'" class="btn btn-default"/> </span>
</div>
</div>
 

<div>

</div>                       

<?php			  
			  }
			  ?>
			       
 <br>
<!--div button next page--> 
<div style="float:left">

 จำนวน
<?= $Num_Rows;?>
&nbsp;โพสต์
<br />
              
              <!--: หน้าที่ -->
			  <?
			  //$Num_Pages;
			  ?> 
              <?
              if($Prev_Page)
              {
                echo " <span style="float:left"><nav>
  <ul class="pagination">
    <li class="disabled"><a href="$_SERVER[SCRIPT_NAME]?Page=$Prev_Page"><span aria-hidden="true">&laquo;</span><span class="sr-only">Previous</span></a></li>
  </ul>
</nav></span> ";
              }
              
              for($i=1; $i<=$Num_Pages; $i++){
                  $Page1 = $Page-2;
                  $Page2 = $Page+2;
                  if($i != $Page && $i >= $Page1 && $i <= $Page2)
                  {
                      echo "<span style="float:left"><nav>
  <ul class="pagination">
    <li class="disabled"><a href="$_SERVER[SCRIPT_NAME]?Page=$i">$i</a></li>
  </ul>
</nav></span>";
                  }
                  elseif($i==$Page)
                  {
                      echo "<span style="float:left"><nav>
  <ul class="pagination">
    <li class="active"><a href="#">$i<span class="sr-only">(current)</span></a></li>
  </ul>
</nav></span>";
                  }
                                              }
              if($Page!=$Num_Pages)
              {
                  echo "<span style="float:left"><nav>
  <ul class="pagination">
    <li class="disabled"><a href="$_SERVER[SCRIPT_NAME]?Page=$Next_Page"><span aria-hidden="true">&raquo;</span><span class="sr-only">Next</span></a></li>
  </ul>
</nav></span>";
              }
			?>
</div>

</div>


nathakarn 180.183.98.xxx 27-11-2014 00:36
 ความคิดเห็นที่ 6
เเก้ได้เเล้วค่ะ ขอบคุณนะค่ะ
จากโค้ดนี้ถ้าเราไม่ต้องการให้เเสดงกระทู้ของผู้ใช้ หรือ merber_id ของผู้ที่ล็อกอิน ไม่ทราบว่าต้องเพิ่มเเงื่อนไขอย่างเราบ้างค่ะ

SELECT a. * , b. * , c. *     
FROM topic a    
LEFT JOIN (    
member b, friend c    
)     
ON a.member_id = b.member_id    
AND a.member_id=c.friend_1  
WHERE   
( a.member_id = '$member_id' )  
OR  
( a.topic_privacy=0 AND c.friend_2='$member_id')   
GROUP BY a.topic_id 






nathakarn 180.183.98.xxx 27-11-2014 01:48
 ความคิดเห็นที่ 7
SELECT a. * , b. * , c. *     
FROM topic a    
LEFT JOIN (    
member b, friend c    
)     
ON a.member_id = b.member_id    
AND a.member_id=c.friend_1  
WHERE   
a.topic_privacy=0 AND c.friend_2='$member_id'  
GROUP BY a.topic_id 


ninenik 58.11.138.xxx 27-11-2014
 ความคิดเห็นที่ 8
เเก้ได้เเล้วค่ะ ขอบคุณนะค่ะ ^^


nathakarn 180.183.102.xxx 27-11-2014 16:01
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ