数据库中已知一个表数据查询另一个表数据的问题
从tb_xmpcps 可以找到用户名$myrow2['xmpcps_user'],然后再通过用户名去tb_user中找到姓名,两个表嵌套查询还真是第一次做,劳大家指点指点!为什么中说$query2有错误?
<?php //查找评分表中相应批次评审状态 $query2=mssql_query("select * from tb_xmpcps where xmpcps_pcid='$xmpc_id'"); $x=1; while($myrow2=mssql_fetch_array($query2)){ ?> <tr> <td height="22" align="center" bgcolor="#FFFFFF"><span class="STYLE1"><?php echo $x;?>.</span></td> <?php //找到与用户名匹配的评委姓名 $query3=mssql_query("select * from tb_user where online_user={$myrow2['xmpcps_user']} limit 1"); $myrow3=mssql_fetch_array($query3); ?>
回复讨论(解决方案)
试试连接表
SELECT B.* FROM tb_xmpcps AS A LEFT OUVER JOIN tb_user AS B ON A.xmpcps_user=B.online_user WHERE A.xmpcps_pcid='$xmpc_id'
$query2=mssql_query("SELECT B.* FROM tb_xmpcps AS A LEFT OUTER JOIN tb_user AS B ON A.xmpcps_user=B.online_user WHERE A.xmpcps_pcid='{$xmpc_id}'");
还是报错啊?为什么?说$query2有错误?劳驾再帮我看看!
<?php //查找评分表中相应批次评审状态 $query2=mssql_query("SELECT B.* FROM tb_xmpcps AS A LEFT OUTER JOIN tb_user AS B ON A.xmpcps"); $x=1; while($myrow2=mssql_fetch_array($query2)){ ?> <tr> <td height="22" align="center" bgcolor="#FFFFFF"><span class="STYLE1"><?php echo $x;?>.</span></td> <td height="22" align="center" bgcolor="#FFFFFF" class="STYLE1"><?php echo $myrow2[online_name];?></td> <td align="center" bgcolor="#FFFFFF" class="STYLE1"><?php echo $myrow2[xmpcps_user];?></td> <td align="center" bgcolor="#FFFFFF"><span class="STYLE1"><?php echo $myrow2[xmpcps_state];?></span></td> </tr> <?php $x++; } ?>
echo mssql_get_last_message();
看看都有什么
我最终还是用两个嵌套查询解决了,这样就可以了,还是感谢大家的帮助!
<?php //查找评分表中相应批次评审状态 $query2=mssql_query("select * from tb_xmpcps where xmpcps_pcid='$xmpc_id'"); $x=1; while($myrow2=mssql_fetch_assoc($query2)){ ?> <tr class="STYLE1"> <td height="22" align="center" bgcolor="#FFFFFF"><span class="STYLE1"><?php echo $x;?>.</span></td> <?php //找到与用户名匹配的评委姓名 $query3=mssql_query("select * from tb_user where online_user='$myrow2[xmpcps_user]'"); $myrow3=mssql_fetch_assoc($query3); ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

Alipay PHP...

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

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
