class_img.php <?phpclass PicInfo
{
// $sql= "select * from userinfo where username='$name' "; //书写sql
public function PicInfo($sql)
{
require_once("db_config.php"); //包含配置信息.
$result= mysql_query($sql, $conn); // 执行查询语句
$this->picInfo = mysql_fetch_array($result); //返回查询结果到数组
$num_rows = mysql_num_rows($result);
mysql_query("set names UTF8");
mysql_close($conn); //关闭数据库连接
$this->getInfo($num_rows); //调用传递信息的方法.
}
// 获取信息传递给属性的方法
private function getInfo($num_rows){
$this->pid = $this->picInfo["PID"];
$this->b_img = $this->picInfo["B_img"];
$this->m_img = $this->picInfo["M_img"];
$this->s_img = $this->picInfo["S_img"];
$this->indicate = $this->picInfo["Indicate"];
$this->type = $this->picInfo["type"];
$this->row = $this->picInfo['row']=$num_rows;
}
//返回每个属性的public 方法.
public function getRow(){
return $this->row;
}
public function getPid(){
return $this->pid;
}
public function getB_img(){
return $this->b_img;
}
public function getM_img(){
return$this->m_img;
}
public function getS_img(){
return$this->s_img;
}
public function getIndicate(){
return$this->indicate;
}
public function getType(){
return$this->type;
}
}
class edit_img
{
public function edit_img($sql)
{
require_once("db_config.php"); //包含配置信息. $result= mysql_query($sql,$conn); // 执行查询语句
$row=mysql_affected_rows(); //返回查询结果到数组
if($row<=0)
{
echo "<script>alert('没插入数据!')</script>";
}
else{
echo "有".$row."组数据受到影响";
mysql_query("set names UTF8");
mysql_close($conn); //关闭数据库连接
//调用传递信息的方法.
}
}
}
?>
read_img.php<?php
include("class_img.php");
$sql="select * from pic_info ";
$show_img= new PicInfo($sql); //创建一个user对象
$indicate=$show_img->getIndicate();
$pid= $show_img->getPid();
$b_img= $show_img->getB_img();
$m_img= $show_img->getM_img();
$s_img=$show_img->getS_img();$row=$show_img->getRow();
if($row>0){
while($row-->=0)
{
echo $s_img;
?>
<li><div class="box"><a href="BackAdmin/annex/<?php echo $b_img ?>"><img src="BackAdmin/annex/smallimg/<?php echo $s_img ?>" alt="web01"></a><h1><?php echo $indicate ?></h1> </div></li>
<?php
}
}?>
不知道什么逻辑上的问题,只返回一行 ,但是查询有2行重复的数据
{
// $sql= "select * from userinfo where username='$name' "; //书写sql
public function PicInfo($sql)
{
require_once("db_config.php"); //包含配置信息.
$result= mysql_query($sql, $conn); // 执行查询语句
$this->picInfo = mysql_fetch_array($result); //返回查询结果到数组
$num_rows = mysql_num_rows($result);
mysql_query("set names UTF8");
mysql_close($conn); //关闭数据库连接
$this->getInfo($num_rows); //调用传递信息的方法.
}
// 获取信息传递给属性的方法
private function getInfo($num_rows){
$this->pid = $this->picInfo["PID"];
$this->b_img = $this->picInfo["B_img"];
$this->m_img = $this->picInfo["M_img"];
$this->s_img = $this->picInfo["S_img"];
$this->indicate = $this->picInfo["Indicate"];
$this->type = $this->picInfo["type"];
$this->row = $this->picInfo['row']=$num_rows;
}
//返回每个属性的public 方法.
public function getRow(){
return $this->row;
}
public function getPid(){
return $this->pid;
}
public function getB_img(){
return $this->b_img;
}
public function getM_img(){
return$this->m_img;
}
public function getS_img(){
return$this->s_img;
}
public function getIndicate(){
return$this->indicate;
}
public function getType(){
return$this->type;
}
}
class edit_img
{
public function edit_img($sql)
{
require_once("db_config.php"); //包含配置信息. $result= mysql_query($sql,$conn); // 执行查询语句
$row=mysql_affected_rows(); //返回查询结果到数组
if($row<=0)
{
echo "<script>alert('没插入数据!')</script>";
}
else{
echo "有".$row."组数据受到影响";
mysql_query("set names UTF8");
mysql_close($conn); //关闭数据库连接
//调用传递信息的方法.
}
}
}
?>
read_img.php<?php
include("class_img.php");
$sql="select * from pic_info ";
$show_img= new PicInfo($sql); //创建一个user对象
$indicate=$show_img->getIndicate();
$pid= $show_img->getPid();
$b_img= $show_img->getB_img();
$m_img= $show_img->getM_img();
$s_img=$show_img->getS_img();$row=$show_img->getRow();
if($row>0){
while($row-->=0)
{
echo $s_img;
?>
<li><div class="box"><a href="BackAdmin/annex/<?php echo $b_img ?>"><img src="BackAdmin/annex/smallimg/<?php echo $s_img ?>" alt="web01"></a><h1><?php echo $indicate ?></h1> </div></li>
<?php
}
}?>
不知道什么逻辑上的问题,只返回一行 ,但是查询有2行重复的数据
这个是只返回一行数据,如需要多行,需要使用while循环