Home  >  Article  >  Backend Development  >  写菜单思路卡主了,求大神

写菜单思路卡主了,求大神

WBOY
WBOYOriginal
2016-06-06 20:34:42991browse

本人PHP菜鸟,遇到了这个问题卡主了,想选择套餐,就直接插入菜品栏,sql语句卡主了。。不知道咋往下写了

A表:bigtype【如图2】 B表:smalltype【如图3】

<code>if(isset($_POST['submit'])){

    $cd=$_POST['bigtype'];
    $query="insert into smalltype·······求大神帮忙····"
}
</code>

写菜单思路卡主了,求大神

写菜单思路卡主了,求大神

写菜单思路卡主了,求大神

回复内容:

本人PHP菜鸟,遇到了这个问题卡主了,想选择套餐,就直接插入菜品栏,sql语句卡主了。。不知道咋往下写了

A表:bigtype【如图2】 B表:smalltype【如图3】

<code>if(isset($_POST['submit'])){

    $cd=$_POST['bigtype'];
    $query="insert into smalltype·······求大神帮忙····"
}
</code>

写菜单思路卡主了,求大神

写菜单思路卡主了,求大神

写菜单思路卡主了,求大神

$query="INSERT INTO smalltype (bid,smalltype)VALUES('".mysql_real_escape_string($bid)."','".mysql_real_escape_string($smalltype)."')";

是用ID去关联2个表吗?
如果是的话,假设前表为A,后表为B
select A.* from A ,B where A.id=B.id and B.bigtype='变量参数';

<code>php</code><code>if(isset($_POST['submit'])){
    $big_type = $_POST['bigtype'];
    $small_type = $_POST['small_type'];
    $query="INSERT INTO smalltype (bid, smalltype)VALUES(".quote($big_type).",".DB::quote($small_type).")";
    DB::query($query);
}
</code>

没有看懂想做什么……
数据库不要增加冗余信息,bigtype和small分两个表的话没有必要把bigtype再复制一遍放到smalltype里,应该在SELECT时用union连起来

应该是根据$cd=$_POST['bigtype'],select B表获取BID,然后再插入A表(BID,smalltype)

这个应该是后台返回全部数据JSON,前端JS控制取比较合适吧。

Statement:
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