您的位置:首页 > 移动开发 > Objective-C

php中使用mysql_fetch_object向页面输出结果,总结!

2013-07-19 09:40 776 查看
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即是对象。我们接下来在控制层对这个对象进行封装进一个二维数组中,这样我们在页面中就很容易的取值。

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


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

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


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

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


是不是对php的数据库操作用加深印象啦呢??哈哈
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: