本文介绍了从后端获取数据,只获取单个字符并添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 创建 表 test ( name varchar ( 20 ), gender varchar ( 20 ), salary varchar ( 20 )); 插入 进入 test 值(' nm1',' male',' 20000' ); 插入 进入 test 值 (' nm2',' female',' 85000'); 插入 进入 test 值 (' nm3',' male',' 1000'); 插入 进入 test 值 (' nm4',' unknown', NULL ); 我是PHP的新手,只是学习。 我有一张桌子样本数据。在显示前面的数据时,为了性别,我必须显示 只有第一个字符,即m / f / u和工资我必须总结前面的总金额,即 使用PHP。 我的表薪水也在varchar中我会把它解析为数字吗? < pre lang = xml > <? php include(' conn.php'); $ result = mysql_query( select *来自测试) 或 die(mysql_error()); echo < table cellpadding ='10'>; echo < tr> < th>名称:< / th> < th>性别:< / th> < th>总薪水:< / th> < / TR GT&;; while($ row = mysql_fetch_array($ result)) { echo < tr>; echo ' < td>'.$row[' name']。 ' < / td>'; echo ' < td>'.$row [' gender']。 ' < / td>'; echo ' < td>'.$row [' salary']。 ' < / td>'; } ?> 解决方案 结果 = mysql_query( select * from test) 或 die(mysql_error()); echo < table cellpadding ='10'>; echo < tr> < th>名称:< / th> < th>性别:< / th> < th>总薪水:< / th> < / TR GT&;; while( row = mysql_fetch_array( result)) { echo < tr>; echo ' < td>' create table test(name varchar(20),gender varchar(20),salary varchar(20));insert into test values ('nm1','male','20000');insert into test values ('nm2','female','85000');insert into test values ('nm3','male','1000');insert into test values ('nm4','unknown',NULL);I am new to PHP, just learning.I''ve a sample data of my table. While showing data in front, for gender I''ve to showonly the first character i.e. m/f/u and for salary I''ve to sum the total amount from front i.eby using PHP.also in my table salary is in varchar would I''ve to parse it as number?<pre lang="xml"><?php include('conn.php'); $result =mysql_query("select * from test") or die(mysql_error()); echo "<table cellpadding = '10'>"; echo "<tr> <th>name:</th> <th>gender:</th> <th>total salary:</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td>'.$row['name'].'</td>'; echo '<td>'.$row['gender'].'</td>'; echo '<td>'.$row['salary'].'</td>'; } ?> 解决方案 result =mysql_query("select * from test") or die(mysql_error()); echo "<table cellpadding = '10'>"; echo "<tr> <th>name:</th> <th>gender:</th> <th>total salary:</th> </tr>"; while(row = mysql_fetch_array(result)) { echo "<tr>"; echo '<td>'. 这篇关于从后端获取数据,只获取单个字符并添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 05:49