2、栏目表数据
3、栏目中文章数量表数据
4、源代码
/db_config.php/
<?php
$mysql_server_name='localhost'; //改本钱身的mysql数据库做事器
$mysql_username='root'; //改本钱身的mysql数据库用户名
$mysql_password='root'; //改本钱身的mysql数据库密码,初始默认密码为空
$mysql_database='echats'; //改本钱身的mysql数据库名
?>
/222.php/
<?php
require(\"大众db_config.php\"大众);
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password) or die(\"大众连接数据库的过程失落败!
\"大众) ;
mysql_query(\"大众set names 'utf8'\公众); //数据库输出编码
mysql_select_db($mysql_database); //打开数据库
//
echo \"大众id,channel为栏目ID在不同表中的字段名称<br>typename,name为栏目名称在不同表中的字段名称<br>COUNT(channel),num为栏眼前内容数量在不同表中的字段名称<br><br>\公众;
echo \"大众栏目表<br>\"大众;
$result1 = mysql_query(\"大众select id,typename from dede_channeltype order by id asc\"大众);
echo \"大众<table border='1'>
<tr>
<th>id</th>
<th>typename</th>
</tr>\"大众;
while($row1 = mysql_fetch_array($result1,MYSQLI_ASSOC)){
echo \公众<tr>\公众;
echo \"大众<td>\"大众 . $row1['id'] . \"大众</td>\公众;
echo \公众<td>\公众 . $row1['typename'] . \"大众</td>\"大众;
echo \"大众</tr>\"大众;
}
echo \"大众</table>\"大众;
echo \"大众栏目中文章数量表<br>\"大众;
$result2 = mysql_query(\"大众select channel,COUNT(channel) AS dd from dede_arctiny GROUP BY channel order by channel asc\公众);
echo \公众<table border='1'>
<tr>
<th>channel</th>
<th>COUNT(channel)</th>
</tr>\"大众;
while($row2 = mysql_fetch_array($result2,MYSQLI_ASSOC)){
echo \"大众<tr>\"大众;
echo \"大众<td>\"大众 . $row2['channel'] . \"大众</td>\"大众;
echo \"大众<td>\"大众 . $row2['dd'] . \公众</td>\公众;
echo \"大众</tr>\"大众;
}
echo \"大众</table>\"大众;
//
echo \"大众组合两张表数据,写入到新表的数据<br>\"大众;
$result = mysql_query(\"大众select if(b.nums,b.nums,0) as num,a.typename as name from dede_channeltype as a left join (select channel,count() as nums from dede_arctiny group by channel) as b on a.id=b.channel\"大众);
echo \"大众<table border='1'>
<tr>
<th>name</th>
<th>num</th>
</tr>\公众;
while($row = mysql_fetch_array($result,MYSQLI_ASSOC)){
echo \"大众<tr>\"大众;
echo \"大众<td>\"大众 . $row['name'] . \"大众</td>\"大众;
echo \公众<td>\"大众 . $row['num'] . \"大众</td>\"大众;
echo \公众</tr>\公众;
//写入新表数据
$sql=mysql_query(\公众replace into test (typename,num) values('\公众.$row['name'].\"大众','\"大众.$row['num'].\"大众')\"大众);
}
echo \"大众</table>\"大众;
//
echo \"大众显示新表的数据<br>\"大众;
$result3 = mysql_query(\"大众select from test\公众);
echo \"大众<table border='1'>
<tr>
<th>Id</th>
<th>name</th>
<th>num</th>
</tr>\公众;
while($row3 = mysql_fetch_array($result3,MYSQLI_ASSOC)){
echo \"大众<tr>\公众;
echo \公众<td>\"大众 . $row3['Id'] . \"大众</td>\"大众;
echo \公众<td>\公众 . $row3['typename'] . \"大众</td>\公众;
echo \"大众<td>\"大众 . $row3['num'] . \公众</td>\公众;
echo \公众</tr>\公众;
}
echo \"大众</table>\"大众;
?>
5、运行结果
5、解释
replace:如果不存在就插入,存在就更新
insert ignore:如果不存在就插入,存在就忽略
只对UNIQUE约束的字段起浸染。