如果数据中有“在……期间使用"项,则用复合键选择项. [英] select item with composite key if there are items in data "using while"

查看:86
本文介绍了如果数据中有“在……期间使用"项,则用复合键选择项.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我想知道当我拥有复合主键时如何从数据库中选择项目

我有这张桌子
sID    cID    item1
1)
当sID和cID是复合主键时
而item1是我要选择的

而且我也想使用此代码选择每个项目(如果有项目的话)

hi every one
I want know how I can select item from database when I have composite primary key

I have this table
sID      cID      item1
 1       cs9        rr

when sID &cID are composite primary key
and item1 is what I want to select

and also I want use this code to select every items if there are items

<?php
$db_name="grade_book";
        $tbl_name="students_course";
        mysql_connect("localhost", "root", "");
        mysql_select_db("$db_name");
$sID=$_SESSION['sID'];
        $sql=mysql_query("SELECT * FROM course WHERE cID in(SELECT cID FROM $tbl_name WHERE sID=$sID)") or die(mysql_error());
        while($mysqlf =mysql_fetch_array($sql))
        {
            $chrs=$mysqlf['chrs'];
            //echo"$sid<br>";
            echo "$chrs<br>";

        }
?>



>>>我知道此选择错误



>>>> I know this select is wrong

推荐答案

db_name = " ;
db_name="grade_book";


tbl_name = 学生课程"; mysql_connect(" " root" "); mysql_select_db("
tbl_name="students_course"; mysql_connect("localhost", "root", ""); mysql_select_db("


db_name" );
db_name");


这篇关于如果数据中有“在……期间使用"项,则用复合键选择项.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆