zoukankan      html  css  js  c++  java
  • php中使用mysql_fetch_object向页面输出结果,总结!

    public function selectResultByThird() {
    		if ((!empty ($_REQUEST["bigname"])) && (!empty ($_REQUEST["secondname"])) && (!empty ($_REQUEST["thirdname"])) && (!empty ($_REQUEST["fourname"])) && (!empty ($_REQUEST["fivename"]))) {
    			$bigid = $_REQUEST["bigname"];
    			$secondid = $_REQUEST["secondname"]; //从页面取得提交的二类
    			$thirdname = $_REQUEST["thirdname"]; //从页面取得提交的三类
    			$fourname = $_REQUEST["fourname"]; //从页面取得提交的四类
    			$fivename = $_REQUEST["fivename"]; //从页面取得提交的五类
    			$start = ($_REQUEST["start"] = '') ? $_REQUEST["start"] : 0; //处理分页用到的变量
    			$limit = ($_REQUEST["limit"] = '') ? $_REQUEST["limit"] : 3;
    			$count_sql = "SELECT * FROM `protein` WHERE expression_system_plant LIKE " . "'$secondid'" .
    			"and protein_name LIKE " . "'$bigid'" . "and country LIKE " . "'$thirdname'" .
    			"and commercialization_process like " . "'$fourname'"."and time like "."'$fivename'";
    			$count = mysql_query($count_sql);
    			$arr = mysql_fetch_object($count);
    			return $arr;
    
    		}
    	}
    

     向页面展示时候,这里用到的是mysql_fetch_object即是对象。我们接下来在控制层对这个对象进行封装进一个二维数组中,这样我们在页面中就很容易的取值。

    1         $data['all'][] = $this->selectInfo_model->selectResultByThird();
    2 //        print_r($data);
    3         $this->load->view('outside/achievement/information_result',$data);

    页面中该怎样输出呢?好吧 ,我们想到的是foreach输出

     1         <?php if(is_array($all)) foreach($all as $r):?>
     2        <tr>
     3            <td width="12%" height="24" align="center"><span class="STYLE5"><?=$r->code_number ?></span></td>
     4         <td width="24%" align="center" height="24"><span class="STYLE5"><?=$r->protein_name?></span></td>
     5         <td width="26%" align="center" hight="30"><span class="STYLE5"><?=$r->expression_system_plant?></span></td>
     6         <td width="13%" align="center"  hight="30"><span class="STYLE5"><?=$r->country?></span></td>
     7         <td width="17%" align="center"  hight="30"><span class="STYLE5"><?=$r->commercialization_process?></span></td>
     8         <td width="8%" align="center"  hight="30"><span class="STYLE5"><?=$r->time?></span></td>
     9        </tr>
    10        <?php endforeach;?>

    现在让我们看看,我们的二维数组到底是什么样的吧,下面是使用啦print_r输出的二维数组

     1 Array
     2 (
     3     [all] => Array
     4         (
     5             [0] => stdClass Object
     6                 (
     7                     [p_id] => 19
     8                     [code_number] => 1001
     9                     [protein_name] => 重组人乳铁蛋白
    10                     [english_name] => Recombinant human lactoferrin (rhLF)
    11                     [country] => 美国
    12                     [commercialization_process] => 上市
    13                     [time] => 2008
    14                     [expression_system_plant] => 水稻
    15                     [development_team] => Ventria Bioscience
    16                     [transgene] => hLF(codon-optimized HLF gene)人工合成413/629
    17                     [vector] => pAPI164,ExpressTecTM
    18                     [promoter] => 水稻胚乳特异性谷蛋白(GT1)
    19                     [terminator] => NOS
    20                     [expression_sites] => 种子
    21                     [expression] => 25%总溶解蛋白;0.5%总谷物
    22                     [no_glycosylation] => 是(植物模式的糖基化,多木糖缺唾液酸)
    23                     [toxicity] => 无毒
    24                     [median_lethal_dose_LD50] => >>1000mg/kg(估算)
    25                     [no_toxicity_concentration_NOAEL] => 1000mg/kg
    26                     [acceptable_daily_intake_ADI] => 10mg/kg(估算)
    27                     [sensitization] => 有潜在致敏性

    是不是对php的数据库操作用加深印象啦呢??哈哈

  • 相关阅读:
    读取.properties配置文件并保存到另一个.properties文件内
    kafka启动报错:另一个程序正在使用此文件,进程无法访问。
    使用Spring boot 嵌入的tomcat不能启动: Unregistering JMX-exposed beans on shutdown
    java把map转json
    java代码生成xml 报错:HIERARCHY_REQUEST_ERR: 尝试在不允许的位置插入节点。
    查询数据库时mapper报错:It's likely that neither a Result Type nor a Result Map was specified.
    获取session
    Apache服务器运维笔记(2)----使用apxs来进行编译安装 mod_txt 模块
    Apache服务器运维笔记(2)----使用<IfDefine>容器实现不同的配置
    Apache服务器运维笔记(1)----运行多个Apache服务器
  • 原文地址:https://www.cnblogs.com/wang3680/p/3199920.html
Copyright © 2011-2022 走看看