Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 多表查询遇到的难题

多表查询遇到的难题

Jun 23, 2016 pm 01:44 PM

要实现 一个需求:通过硬件设备向服务器发出一个请求,
请求带3个参数:
1.用户编码
2.经度
3.纬度


服务器操作:
1.通过经纬度去百度地图获取具体地理地址
2.通过用户编码进行多表查询。获取用户的手机号码。
3.通过取得的地址使用短信网关发送到查询到的手机中
4.短信网关返回发送成功则保存相关数据到mysql



现在问题出在多表查询没有返回手机号码。但是在操作面板则能查询到。是什么问题

流程图:


php代码:

<?php    include_once "config.php";    header("Content-type: text/html; charset=utf8");    $mysql=mysqli_connect($db_host,$db_user,$db_password,$db_name);    mysql_select_db($db_name,$mysql);    mysql_query("SET NAMES 'utf8'");    mysql_query("set character_set_client='utf8'");    mysql_query("set character_results='utf8'");    mysql_query("set collation_connection='utf8'");	$user=$_GET['user'];	$lat=$_GET['lat'];    $lng=$_GET['lng'];    //获取地理地址    date_default_timezone_set('PRC');    $into_time=Date("Y-m-d H:i:s");    $url="http://api.map.baidu.com/geocoder/v2/?ak=E6f2d2e9e662917d0e6eee74ced3db24&callback=renderReverse&location=".$lat.",".$lng."&output=json&pois=1";    $json=file_get_contents($url);    $xjson = substr($json,29,-1);    $point = $lat.'_'.$lng;    $data=json_decode($xjson,true);    $dress = $data['result']['formatted_address'];    file_put_contents("localjson.txt",$data.'--dress--'.$dress);//    $g="select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid='".$user."')";    //多表查询    $g="select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '".$user."')";    $ids= mysql_query($g);    $n=@mysql_fetch_assoc($ids);    $f=$n['id'];    echo '--f--'.$f.'--g--'.$g;?>
Copy after login


回复讨论(解决方案)

求大神

不明白你遇到了什么问题

不明白你遇到了什么问题


就是多表查询时,没获取到查询结果

没看到有多表查询
你先看看子查询 select user_group.userid from user_group where user_group.sqlid = '".$user."')
是否有结果

这个问题,先去看看查询语句是否有结果。。。

没看到有多表查询
你先看看子查询 select user_group.userid from user_group where user_group.sqlid = '".$user."')
是否有结果


这个有结果。。
我原来的sql语句也是可以执行的,在操作面板里是能查询到结果的,如图,
但 是在php里执行却没有查询到号码。mysql有4个总表,如图:

是不是因为这个问题没有查询到数据?

看来你不会调试程序
$ids= mysql_query($g);
改为 $ids= mysql_query($g) or die( $g .'
' . mysql_error());

看来你不会调试程序
$ids= mysql_query($g);
改为 $ids= mysql_query($g) or die( $g .'
' . mysql_error());


3q,改了出现这个:Access denied for user 'root'@'localhost' (using password: NO)

这个信息表示你没有连接数据库,或连接数据库失败

看来你不会调试程序
$ids= mysql_query($g);
改为 $ids= mysql_query($g) or die( $g .'
' . mysql_error());


我在前面已经调用了帐号和密码了的,这是为什么

前面就失败了

前面就失败了


这个要怎么修改

逐步检查,看看是哪一步错了

前面就失败了


有好几个都能连接上,并有返回数据。代码也和这个差不多,为啥这个连接不上

$mysql=mysqli_connect($db_host,$db_user,$db_password,$db_name);
改为:
$mysql=mysql_connect($db_host,$db_user,$db_password);

$g="select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '".$user."')";    $ids= mysql_query($g);    $n=@mysql_fetch_assoc($ids);    $f=$n['id'];
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


你的SQL查询里面仅仅获取了mobile 字段,但是你$f=$n['id'],貌似很不合理啊,获取一个没有select的字段,臣妾做不到啊

$g="select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '".$user."')";    $ids= mysql_query($g);    $n=@mysql_fetch_assoc($ids);    $f=$n['id'];
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


你的SQL查询里面仅仅获取了mobile 字段,但是你$f=$n['id'],貌似很不合理啊,获取一个没有select的字段,臣妾做不到啊



多谢提醒,我现在增加了一项:
  $ids= mysql_query($g,$mysql) or die( $g .'<br>' . mysql_error());
Copy after login

$g="select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '".$user."')";    $ids= mysql_query($g);    $n=@mysql_fetch_assoc($ids);    $f=$n['id'];
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


你的SQL查询里面仅仅获取了mobile 字段,但是你$f=$n['id'],貌似很不合理啊,获取一个没有select的字段,臣妾做不到啊


新增后提示出错:
select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '1409203388')Access denied for user 'root'@'localhost' (using password: NO)
Copy after login
Copy after login
Copy after login

晕死,我是让你修改SQL语句,增加对id字段引用


$g="select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '".$user."')";    $ids= mysql_query($g);    $n=@mysql_fetch_assoc($ids);    $f=$n['id'];
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


你的SQL查询里面仅仅获取了mobile 字段,但是你$f=$n['id'],貌似很不合理啊,获取一个没有select的字段,臣妾做不到啊


新增后提示出错:
select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '1409203388')Access denied for user 'root'@'localhost' (using password: NO)
Copy after login
Copy after login
Copy after login

$g="select akw_user.mobile,akw_user.id from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '".$user."')";    $ids= mysql_query($g);    $n=@mysql_fetch_assoc($ids);    $f=$n['id'];
Copy after login


改这样试试。

晕死,我是让你修改SQL语句,增加对id字段引用



$g="select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '".$user."')";    $ids= mysql_query($g);    $n=@mysql_fetch_assoc($ids);    $f=$n['id'];
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login


你的SQL查询里面仅仅获取了mobile 字段,但是你$f=$n['id'],貌似很不合理啊,获取一个没有select的字段,臣妾做不到啊


新增后提示出错:
select akw_user.mobile from akw_user where akw_user.id in (select user_group.userid from user_group where user_group.sqlid = '1409203388')Access denied for user 'root'@'localhost' (using password: NO)
Copy after login
Copy after login
Copy after login



那个我改为mobile了,现在的情况是
Access denied for user 'root'@'localhost' (using password: NO)
Copy after login

我的#15 就被你忽视了

mysql iiiiiii_connect
mysql_query
说来惭愧一直用框架,加了i的能通用吗

我的#15 就被你忽视了


没有呢,我按你的建议修改了,还是不行哦,同一个做php的朋友,他说是帐号密码对不上。我就纳闷了,比如我前面有好几个返回json的都是使用这个帐号和密码,以正常返回json,为什么多表查询时就会出现这个情况

把你修改后的代码贴出来看看。

把你修改后的代码贴出来看看。

Copy after login

mysql iiiiiii_connect
mysql_query
说来惭愧一直用框架,加了i的能通用吗


  $mysql=mysqli_connect($db_host,$db_user,$db_password);
Copy after login
Copy after login

现在这个就是有i的阿


mysql iiiiiii_connect
mysql_query
说来惭愧一直用框架,加了i的能通用吗


  $mysql=mysqli_connect($db_host,$db_user,$db_password);
Copy after login
Copy after login

现在这个就是有i的阿


谢谢,是这个错了,应该是
mysql_query
Copy after login

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles