Home > Backend Development > PHP Tutorial > How to automatically generate SQL statements

How to automatically generate SQL statements

一个新手
Release: 2023-03-16 13:54:02
Original
3360 people have browsed it

The fields are relatively simple/If necessary, you can customize the fields and sorting yourself/

There are two levels of city linkage. My business needs it, so there are two levels. There are a lot of information on the three levels on the Internet. You can learn from it if you need it. /

Without further ado, let’s look at the renderings first. The code is below


#

    1 <?php 
    2 
    3 // 下面三个变量血缘关系比较近, 在同一省份目录中, 只有id是变化的, 其他两个是固定不变的 
    4 $sort = 31;
    5 $id = $sort*100+1;
    6 $pid = $sort*100;
    7 // $name 是在百度百科搜出来的, 如果格式不一样, 可以自己拆分组合// 建议去百度词条搜, 一般都是下面的格式/ 8 $name = &#39;中西区,东区,南区,湾仔区,九龙城区,观塘区,深水埗区,黄大仙区,油尖旺区 ,离岛区,葵青区,北区,西贡区,沙田区,大埔区,荃湾区,屯门区,元朗区&#39;;
    9 $name = explode(&#39;,&#39;,$name);
    10 map($id,$pid,$sort,$name);
    11 function map($id,$pid,$sort,$name)
    12 {
    13 $count = count($name);
    14 $str = &#39;&#39;;
    15 for($i=0;
    $i<$count;
    $i++)
    16 {
    17 echo "INSERT INTO `xm_official`.`xm_city` (`id`, `parent_id`, `name`, `sort`) VALUES (&#39;".$id."&#39;, &#39;".$pid."&#39;, &#39;".$name[$i]."&#39;, &#39;".$sort."&#39;);
    ";
    18 $id++;
    19 }
    20 }
    21 //访问这个PHP文件, 页面输出的内容就是SQL语句, 直接执行就好了.
    22 ?>
Copy after login

The above is the detailed content of How to automatically generate SQL statements. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template