如何使用会话从多个表中检索数据?

时间:2018-05-19 09:28:47

标签: javascript php html css mysql

我正在做一个动态网站。我的主页面显示了左侧的人物资料和右边的文章。This is my main page。当我点击“阅读更多”时,该特定文章应该在左侧的新页面中打开,并且由同一人撰写的剩余文章应显示在右侧。 但是这里显示的所有文章都是This is the image of my blog page。我只想在左边显示所选文章,在右边显示所有剩余文章。

This is my table for articles。在第一页中,我使用此人的ID呼叫右侧的文章。 这是我的第一页的代码:

 <div class="container">
 <?php
 session_start();
 $q = $_SESSION['id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("demo_db",$con);

$sql="select * from person_details where id=$q";
$res=mysql_query($sql);
while($ar=mysql_fetch_array($res))
{
	
	
?>
<div>
  <div class="row">
  	<div style="background-color:rgba(125, 178, 194, 0.43); margin-bottom:10px;" class="col-sm-8 col-md-8 col-lg-8">
  		<div class="row">
  			<div class="col-sm-4 col-md-4 col-lg-4">
  				<img style="margin:20px;" src="uploads/<?php echo $ar[17]; ?>">
  			</div>
  			<div class="col-sm-8 col-md-8 col-lg-8">
 	 			<h3><b>Mr. <?php echo $ar[1];?></b></h3>
 	 			<h5><?php echo $ar[8];?>, <?php echo $ar[12];?></h5>
  				<h5><?php echo $ar[2];?>, <?php echo $ar[7];?> years of experience</h5>
  				<p><?php echo $ar[16];?></p>
 			</div>
  		</div>
       <div style="margin:20px;">
        <h4><b>Services</b></h4>
        <hr>
        <ul>
       	 <li>
        	<h5><?php echo $ar[18]; ?></h5>
       	 </li>
        </ul>
        <h4><b>Specialisations</b></h4>
        <hr>
        	<ul>
        		<li>
        			<h5><?php echo $ar[2]; ?></h5>
       			 </li>
        	</ul>
        <h4><b>Education</b></h4>
        <hr>
        	<ul>
       			 <li>
        			<h5><?php echo $ar[8]; ?> - <?php echo $ar[9]; ?> , <?php echo $ar[10]; ?> , <?php echo $ar[11];?></h5>
        		</li>
        	</ul>
       		 <ul>
        	<li>
      		  <h5><?php echo $ar[12]; ?> - <?php echo $ar[13]; ?> , <?php echo $ar[14]; ?> , <?php echo $ar[15];?></h5>
        </li>
        </ul>
        
        </div>
        
  	</div>
    
  <div class="col-sm-4 col-md-4 col-lg-4">
  <h3>Articles by Mr. <?php echo $ar[1];?></h3><?php } ?>
  <hr>
  <?php
  $sql1="select * from article_tb where id=$q";
$res1=mysql_query($sql1);
while($ar=mysql_fetch_array($res1))
{
	$_SESSION['id'] = $q;
	?>
  <h4><b><?php echo $ar[1]; ?></b></h4>
  	<div class="row">
  		<div class="col-sm-6 col-lg-6 col-md-6">
  			<img src="uploads/<?php echo $ar[3]; ?>" width="170px" height="88">
  		</div>
 		 <div class="col-sm-6 col-md-6 col-lg-6">
 			  <?php echo $ar[5]; ?>
 			&nbsp; <form action="blog.php">
<input type="submit" class="btn btn-info" name="read" value="read more" />
</form>
  		</div>
 	 </div>
      <hr>
 
 
  
 
  
<?php } ?></div>
</div>

  </div>
这是我的第二页的代码:

 <div class="container">
 <?php
 session_start();
 
 $q = $_SESSION['id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("demo_db",$con);
$sql="select * from article_tb where id=$q";
$res=mysql_query($sql);
while($ar=mysql_fetch_array($res))
{
?>
<div>
  <div class="row">
  	<div style="border:1px solid #005212;"  class="col-sm-8 col-md-8 col-lg-8">
  		<div class="row">
  			<center><img style="margin-top:10px;" src="uploads/<?php echo $ar[3]; ?>" /></center>
            <div  class="col-sm-12 col-md-12 col-lg-12">
          <h4><b><?php echo $ar[1]; ?></b></h4>
          <p><?php echo $ar[2]; ?></p>
          </div>
        </div>
      
  	</div>
    
  <div class="col-sm-4 col-md-4 col-lg-4">
  
  
  <h4><b><?php echo $ar[1]; ?></b></h4>
  	<div class="row">
  		<div class="col-sm-6 col-lg-6 col-md-6">
  			<img src="uploads/<?php echo $ar[3]; ?>" width="170px" height="88" />
  		</div>
 		 <div class="col-sm-6 col-md-6 col-lg-6">
        <?php echo $ar[5]; ?>
 			 &nbsp; <form action="blog.php">
<input type="submit" class="btn btn-info" name="read" value="read more" />
</form>
  		</div>
 	 </div>
      <hr>
  
  </div></div></div>
  
<?php } ?>
有人可以帮帮我吗?

0 个答案:

没有答案