0

可能重复:
如何在 php 中显示两个具有相同数据的不同表的信息,但名称或 id 不同

此代码显示表的两个信息只想显示我选择的一个表信息

因为有两个表菜单和非菜单。

并且在这 2 个表中,n 个字段和项目作为输入给出,所以当我选择表中的一个项目时,将显示这些项目的信息

因为当我选择表格的特定项目时,它会同时显示表格信息。

任何尝试n帮助..

<?php
session_start();
if(isset($_GET['id']))
{
    $_SESSION['n']=$_GET['id'];
}

$n=$_SESSION['n'];

$con=mysql_connect("localhost","root","");
mysql_select_db("menu",$con);
$sql="select * from menus where id=$n";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
echo "<table border=0 width=100%  ><tr>";
echo "<td><h1><img src=\"images/veg.jpg\" height=35 width=35  /> $row[tittle]</h1></td>"; ?> 
<?php echo" <td><h1><img src=\"images/telephone1.jpg\" height=35 width=35  /> $row[phone]    </h1></td>";
//<img src="images/Kapu-Lighthouse.jpg"  title="Non veg" width="210" height="150" />

//echo " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>";
// echo "- $row[phone]"; 
echo "</tr></table>";
?> 
    <img src="upload/<?php  echo $row['photo'];?>" height=300 width= 550 alt="" />
    <?php
echo "<br> <a href=index.php>back</a>";


?>                    

   <?php
    echo"<h4>$row[address]</h4>";
   ?>          
<h1>Gallery</h1>

<table  border=7  cellspacing=10 > <tr>

<td><img src="upload/<?php  echo $row['gallery'];?>" height=150 width= 160 alt="" /> </td>
  <td><img src="upload/<?php  echo $row['gallery1'];?>"height=150 width= 160 /> </td>
  <td><img src="upload/<?php  echo $row['gallery2'];?>"height=150 width= 160 /> </td>
  <td><img src="upload/<?php  echo $row['gallery3'];?>"height=150 width= 160 /> </td>
  <td><img src="upload/<?php  echo $row['gallery4'];?>"height=150 width= 160 /> </td>
</tr>
</table>
<?php mysql_close($con);   ?>
<!-- End veg items to be displayed in menu.php -->


 <!-- Non veg items to be displayed in menu.php -->
         <?php



                    if(isset($_GET['nid']))

{
    $_SESSION['n']=$_GET['nid'];
}

$n=$_SESSION['n'];


$con=mysql_connect("localhost","root","");
mysql_select_db("menu",$con);
$sql="select * from nonmenu where id=$n";
echo "$sql";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);

echo "<table border=0 width=100%  ><tr>";
echo "<td><h1><img src=\"images/non-veg.jpg\" height=35 width=35  /> $row[ntittle]</h1></td>"; ?> 
<?php echo" <td><h1><img src=\"images/telephone1.jpg\" height=35 width=35  /> $row[nphone]    </h1></td>";
//<img src="images/Kapu-Lighthouse.jpg"  title="Non veg" width="210" height="150" />

//echo " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>";
// echo "- $row[phone]"; 
echo "</tr></table>";
?> 
    <img src="upload/<?php  echo $row['nphoto'];?>" height=300 width= 550 alt="" />
    <?php
echo "<br> <a href=index.php>back</a>";


?>                    

   <?php
    echo"<h4>$row[naddress]</h4>";
   ?>          
<h1>Gallery</h1>

<table  border=7  cellspacing=10 > <tr>

<td><img src="upload/<?php  echo $row['ngallery'];?>" height=150 width= 160 alt="" /> </td>
  <td><img src="upload/<?php  echo $row['ngallery1'];?>"height=150 width= 160 /> </td>
  <td><img src="upload/<?php  echo $row['ngallery2'];?>"height=150 width= 160 /> </td>
  <td><img src="upload/<?php  echo $row['ngallery3'];?>"height=150 width= 160 /> </td>
  <td><img src="upload/<?php  echo $row['ngallery4'];?>"height=150 width= 160 /> </td>
</tr>
</table>
<?php mysql_close($con); ?>
<!-- End Non veg items to be displayed in menu.php -->




        </div>
    </div>
4

1 回答 1

0

使主题独占。如果我理解正确,这可能会起作用:

if(isset($_GET['id']) && (!isset($_GET['nid']))) {
// id tasks
die;
}

if(isset($_GET['nid']) && (!isset($_GET['id'])) ) { 
// nid tasks
die;
}

更新:

<?php
session_start();
if ( isset( $_GET[ 'id' ] ) && ( !isset( $_GET[ 'nid' ] ) ) ) {
  $_SESSION[ 'n' ] = $_GET[ 'id' ];
  $n = $_SESSION[ 'n' ];
  $con = mysql_connect( "localhost", "root", "" );
  mysql_select_db( "menu", $con );
  $sql    = "select * from menus where id=$n";
  $result = mysql_query( $sql );
  $row    = mysql_fetch_array( $result );
  echo "<table border=0 width=100%  ><tr>";
  echo "<td><h1><img src=\"images/veg.jpg\" height=35 width=35  /> $row[tittle]</h1></td>";
 ?>

<?php echo" <td><h1><img src=\"images/telephone1.jpg\" height=35 width=35  /> $row[phone]    </h1></td>";
  //<img src="images/Kapu-Lighthouse.jpg"  title="Non veg" width="210" height="150" />
  //echo " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>";
  // echo "- $row[phone]";
  echo "</tr></table>";
  ?>
<img src="upload/<?php  echo $row[ 'photo' ];?>" height=300 width=550 alt="" />
<?php
  echo "<br> <a href=index.php>back</a>";
  echo"<h4>$row[address]</h4>";
  ?>
<h1>Gallery</h1>
<table border=7 cellspacing=10>
  <tr>
    <td><img src="upload/<?php  echo $row[ 'gallery' ];?>" height=150 width=160 alt="" /></td>
    <td><img src="upload/<?php  echo $row[ 'gallery1' ];?>" height=150 width=160 /></td>
    <td><img src="upload/<?php  echo $row[ 'gallery2' ];?>" height=150 width=160 /></td>
    <td><img src="upload/<?php  echo $row[ 'gallery3' ];?>" height=150 width=160 /></td>
    <td><img src="upload/<?php  echo $row[ 'gallery4' ];?>" height=150 width=160 /></td>
  </tr>
</table>
<?php mysql_close( $con ); ?>
<!-- End veg items to be displayed in menu.php -->
<!-- Non veg items to be displayed in menu.php -->
<?php
}; die;
if ( isset( $_GET[ 'nid' ] ) && ( !isset( $_GET[ 'id' ] ) ) ) {
  $_SESSION[ 'n' ] = $_GET[ 'nid' ];
  $n = $_SESSION[ 'n' ];
  $con = mysql_connect( "localhost", "root", "" );
  mysql_select_db( "menu", $con );
  $sql = "select * from nonmenu where id=$n";
  echo "$sql";
  $result = mysql_query( $sql );
  $row    = mysql_fetch_array( $result );
  echo "<table border=0 width=100%  ><tr>";
  echo "<td><h1><img src=\"images/non-veg.jpg\" height=35 width=35  /> $row[ntittle]</h1></td>"; ?>
<?php echo" <td><h1><img src=\"images/telephone1.jpg\" height=35 width=35  /> $row[nphone]    </h1></td>";
  //<img src="images/Kapu-Lighthouse.jpg"  title="Non veg" width="210" height="150" />
  //echo " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>";
  // echo "- $row[phone]";
  echo "</tr></table>";
  ?>
<img src="upload/<?php  echo $row[ 'nphoto' ];?>" height=300 width=550 alt="" />
<?php
  echo "<br> <a href=index.php>back</a>";
  echo"<h4>$row[naddress]</h4>";
  ?>
<h1>Gallery</h1>
<table border=7 cellspacing=10>
  <tr>
    <td><img src="upload/<?php  echo $row[ 'ngallery' ];?>" height=150 width=160 alt="" /></td>
    <td><img src="upload/<?php  echo $row[ 'ngallery1' ];?>" height=150 width=160 /></td>
    <td><img src="upload/<?php  echo $row[ 'ngallery2' ];?>" height=150 width=160 /></td>
    <td><img src="upload/<?php  echo $row[ 'ngallery3' ];?>" height=150 width=160 /></td>
    <td><img src="upload/<?php  echo $row[ 'ngallery4' ];?>" height=150 width=160 /></td>
  </tr>
</table>
<?php
  mysql_close( $con );
//End Non veg items to be displayed in menu.php
}; die;
?>
</div>
</div>
于 2012-11-15T07:02:02.880 回答