dousi1994 2013-06-14 23:28
浏览 32

我可以查询2列在Mysql中返回1行吗?

The company database has duplicate entries for ID due to different locations so I'm trying to return the database queries on the website by ID # AND zip matches. I can get the the code to query the database and not return an error but it won't return the values in the results(only blank entries) from the row it found.

Any ideas?

$mysqli = new mysqli($host, $user, $password, $dbname);
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
}        
$searchTerm = $_GET['term']; // GET the search term submitted by the form
$zip = $_GET['term1'];
            $customerNumber = '';
            $progID = '';
            $balance = '';



            $sql = "Select cust_no, zip From teecust where cust_no=? and zip=?";

            // Create the prepared statement
            if($stmt = $mysqli->prepare($sql)){
                $stmt->bind_param("ss", $searchTerm, $zip); // bind the search term to the query where the '?' once was
                if(!$stmt->execute()){ // run the query
    echo $mysqli->error;
    }; 
                $stmt->bind_result($customerNumber, $progID, $balance); // retrieve results into variables
                while($stmt->fetch()){ // loop through results
                    // You now have the result in $customerNumber, $progID, and $balance - do what    you want with it
echo "Customer number: " . $customerNumber . "<br>Date last updated on: " . $progID . "<br> Balance: <strong>$" . $balance . "</strong> ";
                }
                $stmt->close();
            }
        else{
        echo $mysqli->error;
        }

            ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分