数组PHP-Transforming
我通过查询从数据库中获取一些数据,然后通过While循环进行循环:数组PHP-Transforming,php,arrays,variables,Php,Arrays,Variables,我通过查询从数据库中获取一些数据,然后通过While循环进行循环: $r=mysql_query("SELECT * FROM advertisement_packages"); while($a = mysql_fetch_assoc($r)): echo $a['exposure]; //This prints out 1,2,3,4 endwhile; 我该怎么做,所以exposure=1是exposure=1=Mini和exposure=2=Standard等。如果结构为: if
$r=mysql_query("SELECT * FROM advertisement_packages");
while($a = mysql_fetch_assoc($r)):
echo $a['exposure]; //This prints out 1,2,3,4
endwhile;
我该怎么做,所以exposure=1是exposure=1=Mini和exposure=2=Standard等。如果结构为:
if ($a['exposure'] == 1){
echo "Mini";
}
elseif($a['exposure'] == 2){
echo "Standard";
}
$exposures = array(
1 => 'Mini',
2 => 'Standard',
// and so forth
);
while($a = mysql_fetch_assoc($r)):
echo $exposures[ $a['exposure'] ];
endwhile;
只需我的$0.02,代码就更清晰了。如果结构:
$exposures = array(
1 => 'Mini',
2 => 'Standard',
// and so forth
);
while($a = mysql_fetch_assoc($r)):
echo $exposures[ $a['exposure'] ];
endwhile;
仅使用我的$0.02,使代码更清晰。**另一个好方法是在数据库中维护一个表结构,将曝光编号与其描述关联起来。通过这种方式,您可以直接从数据库中显示曝光描述(也可以从曝光信息表中填充web表单上的下拉菜单)。只需遵循示例SQL,看看您是否理解** 创建表photo\u客户端( id INT自动递增主键, 客户名称VARCHAR(100), 暴露锡 ); 创建表格曝光信息( 曝光INT自动增量主键, 描述VARCHAR(100) ); 在曝光信息(说明)中插入值('mini')、('standard')、('poster') 在照片中插入客户(客户名称、曝光)值('John Doe',2),('Jane Smith',1),('Johnny Walker',3) 选择a.client_name作为客户端,b.description作为照片_客户端a中的曝光,曝光信息b,其中a.exposure=b.exposure 上述语句的输出应该如下所示:
client exposure
------------------------
Jane Smith mini
John Doe standard
Johnny Walker poster
**另一个好方法是在数据库中维护一个表结构,将曝光编号与其描述相关联。通过这种方式,您可以直接从数据库中显示曝光描述(也可以从曝光信息表中填充web表单上的下拉菜单)。只需遵循示例SQL,看看您是否理解** 创建表photo\u客户端( id INT自动递增主键, 客户名称VARCHAR(100), 暴露锡 ); 创建表格曝光信息( 曝光INT自动增量主键, 描述VARCHAR(100) ); 在曝光信息(说明)中插入值('mini')、('standard')、('poster') 在照片中插入客户(客户名称、曝光)值('John Doe',2),('Jane Smith',1),('Johnny Walker',3) 选择a.client_name作为客户端,b.description作为照片_客户端a中的曝光,曝光信息b,其中a.exposure=b.exposure 上述语句的输出应该如下所示:
client exposure
------------------------
Jane Smith mini
John Doe standard
Johnny Walker poster
什么?你能提出你的问题吗?你想打印“曝光量=1”,“曝光量=2”?什么?你能提出你的问题吗?你想打印“曝光量=1”,“曝光量=2”?