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的数据库操作用加深印象啦呢??哈哈
相关文章推荐
- php中使用mysql_fetch_array输出数组至页面中展示
- PHP使用mysql_fetch_object从查询结果中获取对象集的方法
- 使用mysql_fetch_object()以对象的形式返回查询结果
- 深入分析使用mysql_fetch_object()以对象的形式返回查询结果
- 深入分析使用mysql_fetch_object()以对象的形式返回查询结果
- 深入分析使用mysql_fetch_object()以对象的形式返回查询结果
- PHP使用zlib扩展实现页面GZIP压缩输出
- 如何将PHP的结果输出到非PHP页面中
- PHP使用zlib扩展实现页面GZIP压缩输出
- php示例代码之使用mysql_fetch_object函数
- PHP中PDO对像及PDOStatement::fetch()的用法数据库查询,结果输出处理
- PHP: 使用mysql_fetch_array()来获取数据
- 使用mysql_fetch_row()以数组的形式返回查询结果
- 妙味课堂中使用php,MySQL,ajax制作简易的新浪微博页面
- php示例代码之使用mysql_fetch_object函数
- 【旧资料整理】php mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc,msql_fetch_object的区别
- [乐意黎转载]PHP mysql_fetch_object() 函数
- php中使用mysql_stmt(预处理语句)来处理select查询结果
- php中的mys ql函数使用 mysqlfetcharray
- 饼干是这样压缩的——PHP使用zlib扩展实现页面GZIP压缩输出