douxiajiao8445 2013-10-24 11:59
浏览 26
已采纳

返回错误''没有选择数据库'

I am trying to return data from two tables. I am getting a No database selected error. I am only learning so go easy on me your common sense. I thought I had the database selected up top, am I missing something some where else or have i just made another mess!? The first 6 td's are from the first table (custrec), the rest from table (contidr) Here's the code

<?php
//connect to database
$mysqli = new mysqli('localhost', 'name', 'pass', 'Org_db');

// check connection
    if (mysqli_connect_errno()) {
      echo "Connect failed: " . mysqli_connect_errno(); exit();
    }

$result = mysql_query("SELECT * FROM `custrec` 
          FULL OUTER JOIN `contidr` ON contidr.cid = custrec.`cid` WHERE custrec.`cid` = `1`");
if($result === FALSE) {
    die(mysql_error()); //  error handling
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title>Get queries - multiple Customer and contact details</title>

</head>

<body>
    <table width="80%" border="1px">
      <tr>
        <th scope="col">Customer ID</th>
        <th scope="col">Customer type</th>
        <th scope="col">Number of Children</th>
        <th scope="col">Animal Preference</th>
        <th scope="col">Vet ID</th>
        <th scope="col">Individual Contact ID Number</th>
        <th scope="col">First Name</th>
        <th scope="col">Last Name</th>
        <th scope="col">Address L1</th>
        <th scope="col">Address L2</th>
        <th scope="col">Town/City</th>
        <th scope="col">State</th>
        <th scope="col">Postcode</th>
        <th scope="col">Email</th>
        <th scope="col">Postcode</th>
      </tr>
<?php

while ($row = mysql_fetch_array($result)) {
?>
  <tr>
    <td><? echo $row["$cid"]; ?></td>
    <td><? echo $row["$cust_type"]; ?></td>
    <td><? echo $row["$no_chd"]; ?></td>
    <td><? echo $row["$aPref"]; ?></td>
    <td><? echo $row["$vetId"]; ?></td>
    <td><? echo $row["$icin"]; ?></td>
    <td><? echo $row["$id_type"]; ?></td>
    <td><? echo $row["$first_name"]; ?></td>
    <td><? echo $row["$last_name"]; ?></td>
    <td><? echo $row["$add_li1"]; ?></td>
    <td><? echo $row["$add_li2"]; ?></td>
    <td><? echo $row["$town_city"]; ?></td>
    <td><? echo $row["$state"]; ?></td>
    <td><? echo $row["$postcode"]; ?></td>
    <td><? echo $row["$email"]; ?></td>
    <td><? echo $row["$ph_area_code"]; ?></td>
    <td><? echo $row["$phone"]; ?></td>
    <td><? echo $row["$mobile"]; ?></td>   
  </tr>
<?php } 

/* close connection */
 $mysqli->close();
?>
</table>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongxian5735 2013-10-24 12:40
    关注

    As it was noted in comments, you are mixing mysql and mysqli. And this is your problem.

    For mysqli you already selected database but later you are using mysql functions, which causes the error. You have to use only mysqli functions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B