php怎么样mysql获取表字段名mysql表中所有字段名到一个数组

| Copyright &
. All Rights Reserved .> PHP使用mysql_fetch_row()函数逐行获取结果集中的每条记录作为枚举数组PHP使用mysql_fetch_row()函数逐行获取结果集中的每条记录作为枚举数组PHP使用mysql_fetch_row()函数逐行获取结果集中的每条记录作为枚举数组
PHP中的mysql_fetch_row()函数可以逐行获取结果集中的每条记录作为枚举数组。在应用mysql_fetch_row()函数逐行获取结果集中的记录时,只能使用数字索引来读取数组中的数据。
mysql_fetch_row()函数返回的数组的下标从0开始,即以$row[0]的形式访问第一个元素,只有一个元素时也是如此。
下面获取db_xuesheng数据库中的tb_chengji表中的学生成绩,并使用mysql_fetch_row()函数逐行获取结果集中的记录,并放入到一个数组中,然后使用while语句循环输出学生名称及成绩。
&meta http-equiv="Content-Type" content="text/ charset=gb2312" /&
&title&PHP使用mysql_fetch_row()函数逐行获取结果集中的每条记录作为枚举数组示例-&/title&
// mysql_connect()函数连接MySQL数据库服务器
$conn=mysql_connect("localhost","root","123") or die("连接MySQL数据库服务器失败!".mysql_error());
// mysql_select_db()函数选择数据库db_xuesheng
mysql_select_db("db_xuesheng",$conn);
// mysql_query()函数
$arr=mysql_query("select * from tb_chengji",$conn);
&table border="1" width="100%"&
&th&学生名称&/th&
&th&语文&/th&
&th&数学&/th&
&th&英语&/th&
$row=mysql_fetch_row($arr);
if($row==false){
echo '&tr&&td colspane="2"&对不起!您检索的信息不存在。&/td&&/tr&';
// 使用while语句循环输出mysql_fetch_row()函数返回的数组中的信息
while($result=$row){
&td&&?php echo $result[1];?&&/td&
&td&&?php echo $result[2];?&&/td&
&td&&?php echo $result[3];?&&/td&
&td&&?php echo $result[4];?&&/td&
} // 结束while循环
在浏览器中查看PHP使用mysql_fetch_row()函数从结果集中获取一行作为枚举数组的显示效果。如下图所示:
使用mysql_fetch_array()函数获取的数组可以是数字索引数组,也可以是关联数组,而使用mysql_fetch_row()函数获取的数组,只可以为数字索引数组。
精华推荐&&&&&&&&&&&&&&&&&&&&&&&&&&&&&Copyright&
All Rights Reservedmysql获取指定数据库所有表名和获取指定表所有字段名
博客搬家到我自己的博客了,这里只是一个索引,地址:去看看
最新教程周点击榜
微信扫一扫怎么样在PHP中将MySQL的查询结果转换为数组并用where拼接? _ 路由器设置|192.168.1.1|无线路由器设置|192.168.0.1 - 路饭网
您的位置: >
> 阅读资讯:怎么样在PHP中将MySQL的查询结果转换为数组并用where拼接?
怎么样在PHP中将MySQL的查询结果转换为数组并用where拼接?
怎么样在PHP中将MySQL的查询结果转换为数组并用where拼接?
mysql查询结果转换为PHP数组的几种方法的区别:
$result = mysql_fetch_row():这个函数返回的是数组,数组是以数字作为下标的,你只能通过$result[0],$Result[2]这样的形式来引用。
$result = mysql_fetch_assoc():这个函数返回是以字段名为下标的数组,只能通过字段名来引用。$result['field1'].
$result = mysql_fetch_array():这个函数返回的是一个混合的数组,既可以通过数字下标来引用,也可以通过字段名来引用。$result[0]或者$result[&field1&].
$result = mysql_fetch_object():以对象的形式返回结果,可以通过$result-&field1这样的形式来引用。
建议使用mysql_fetch_assoc()或者mysql_fetch_array,这两个函数执行速度比较快,同时也可以通过字段名进行引用,比较清楚。
where拼接技巧
将where语句从分支移到主干,解决where在分支上的多种情况,分支条件只需and 连接即可如where1==1等
$sql=&SELECT * FROM bb where true &;
因为使用添加了&1=1&的过滤条件以后数据库系统就无法使用索引等查询优化策略,数据库系统将会被迫对每行数据进行扫描(也就是全表扫描)以比较此行是否满足过滤条件,当表中数据量比较大的时候查询速度会非常慢。优化方法
&td&商品名称:&/td&
&td width=&200&&&input type=&text& class=&text& name=&kit_name& id=&fn_kit_name&/&&/td&
&td align=&right&&备案开始日期:&/td&
&td width=&200&&&input type=&text& name=&search[or_get_reg_date]&/&&img src=&images/data.jpg& /&&/td&
&td&备案结束日期:&/td&
&td width=&200&&&input type=&text& name=&search[lt_reg_date]&/&&img src=&images/data.jpg& /&&/td&
&td&产品经理:&/td&
&td&&input type=&text& class=&text& name=&search[managerid]&/&&/td&
$postData = array(
'managerid' =& '21',
'or_get_reg_date' =& '09',
'lt_reg_date' =& '',
'in_id' =& array(1, 2, 3),
$tmpConditions = transArrayTerms($postData);
echo $whereCause = getWhereSql($tmpConditions);
// WHERE managerid like '21%' OR reg_date&'09' AND reg_date&'' AND id in ('1','2','3')
处理where条件的sql
* 表单提交值转化成where拼接数组
function transArrayTerms($infoSearch) {
$aryRst = array();
$separator = array('lt'=&'&', 'let'=&'&=', 'gt'=&'&', 'get'=&'&=', 'eq'=&'=', 'neq'=&'&&');
foreach ($infoSearch as $term =& $value) {
if (empty($value))
if (strpos($term, &or_&) !== false) { //添加or连接符
$terms['useOr'] =
$name = str_replace(&or_&, &&, $term);
if (strpos($name, &in_&) !== false) {
$terms['name'] = str_replace(&in_&, &&, $name);
$terms['charCal'] = & in &;
$terms['value'] = &('& . implode(&','&, $value) . &')&;
$terms['name'] = $
$terms['charCal'] = & like &;
$terms['value'] = &'& . trim($value) . &%'&;
//放在else后面
foreach($separator as $charCalName =&$charCalVal){
if (strpos($name, $charCalName.&_&) !== false) {
$terms['name'] = str_replace($charCalName.&_&, &&, $name);
$terms['charCal'] = $charCalV
$terms['value'] = &'& . trim($value) . &'&;
$aryRst[] = $
unset($terms);
return $aryR
function whereOperator($has_where, $useOr) {
$operator = $has_where ? ($useOr === false ? ' AND ' : ' OR ') : ' WHERE ';
* aryTerm transArrayTerms转化后的查询条件
* @过滤没有输入的sql查询条件并转化成where条件.
function getWhereSql($aryTerm) {
$whereCause = '';
if (count($aryTerm) & 0) {
$has_where = '';
foreach ($aryTerm as $value) {
$has_where = whereOperator($has_where, isset($value['useOr']));
$whereCause .= $has_where . $value['name'] . $value['charCal'] . $value['value'];
return $whereC
本文地址:
相关文章列表查看: 4524|回复: 8
读取v9数据库中字段值为数组的方法
高手请略过……
v9中有的字段值是数组,直接使用其中的值,其实解决方法很简单的。
{pc:get sql=&select * from v9_news_data where id=17&}
{loop $data $r}
$str=$r[content_pic];
eval(&\$str = $&);
for($i=0;$i&count($str);$i++){
echo $str[$i]['url'];
谢谢分享啊 来学学
以前遇到过的问题,现在解决了
楼主好人啊,论坛里缺的就是你这样的人
谢谢分享了,学习了。
又学到了一招啊
{php eval(&\$arr=& . $r[setting] . &;&);echo $arr[1]['imageurl'];}
1可以修改成你想要的。
楼主果然是好人啊
不是高手的,只能向你学习啊
Powered by

我要回帖

更多关于 mysql 字段存数组 的文章

 

随机推荐