此代码显示表的信息 只想显示我选择的一个表信息
因为有两个表菜单和非菜单。
在这两个表中,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>
答案 0 :(得分: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>