Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查询的前半部分可以工作,但后端不能_Php_Sorting - Fatal编程技术网

Php 查询的前半部分可以工作,但后端不能

Php 查询的前半部分可以工作,但后端不能,php,sorting,Php,Sorting,我以前曾发布过这篇文章,但无法清楚地解释,所以重新发布 我使用了这个查询。我需要按$variis排序,但似乎排序不起作用。我仔细检查了字段名和表。查询可以工作,但不会按$variis对其进行排序。我也尝试过在help_box.status周围使用括号,但它不起作用 代码: //Unseen $variis = "Need Help"; $myid = <the user id>; $sql = "select car_help.car_id, agent_names.agent_n

我以前曾发布过这篇文章,但无法清楚地解释,所以重新发布

我使用了这个查询。我需要按$variis排序,但似乎排序不起作用。我仔细检查了字段名和表。查询可以工作,但不会按$variis对其进行排序。我也尝试过在help_box.status周围使用括号,但它不起作用

代码:

//Unseen
$variis = "Need Help";
$myid = <the user id>;

$sql = "select car_help.car_id, agent_names.agent_name, help_box.status, 
car_help.why_car, car_help.date_time_added, car_help.just_date, 
car_help.type, agent_names.agent_id
from car_help LEFT JOIN agent_names on car_help.agent_whois = agent_names.agent_id 
LEFT JOIN help_box on car_help.somefield= help_box.somefield
where agent_names.system_id = '$myid' and car_help.system_id='$myid' 
and added_by <> '$myid' and help_box.status = '$variis'
UNION
select magazine_help.note_id, agent_names.agent_name, help_box.status, 
magazine_help.note_name, magazine_help.date_time_added, 
magazine_help.just_date, magazine_help.type, agent_names.agent_id
from magazine_help LEFT JOIN agent_names on 
magazine_help.agent_id = agent_names.agent_id 
LEFT JOIN help_box on car_help.somefield= help_box.somefield 
where agent_names.system_id='$myid' and 
magazine_help.system_id = '$myid' and added_by <> '$myid' 
and help_box.status = '$variis'
UNION
select motorcycle_help.rand_id, agent_names.agent_name, 
help_box.status, motorcycle_help.rand_name, motorcycle_help.date_time_added,     
motorcycle_help.just_date, motorcycle_help.type, agent_names.agent_id
from motorcycle_help LEFT JOIN agent_names ON 
motorcycle_help.by_who = agent_names.agent_id
LEFT JOIN help_box on car_help.somefield= help_box.somefield
where agent_names.system_id = '$myid' and 
motorcycle_help.system_id='$myid' and added_by <> '$myid' 
and help_box.status = '$variis'
UNION
select mobile_questions.bal_test_id, agent_names.agent_name, 
help_box.status, mobile_questions.bal_why, mobile_questions.date_time_added,   
mobile_questions.just_date, mobile_questions.type, agent_names.agent_id
from mobile_questions LEFT JOIN agent_names ON 
mobile_questions.agent_who_ordered = agent_names.agent_id
LEFT JOIN help_box on car_help.somefield= help_box.somefield
where agent_names.system_id = '$myid' and 
mobile_questions.system_id='$myid' and added_by <> '$myid' 
and help_box.status = '$variis'
ORDER BY date_time_added DESC LIMIT $startrow, 20";

$result = mysql_query($sql);

$query = mysql_query($sql) or die ("Error: ".mysql_error());


if ($result == "")
{
echo "";
}
echo "";


$rows = mysql_num_rows($result);

if($rows == 0)
{
print("");

}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{

$row1 = $row['row_name'];


print("$row1");
}

}

如果要对结果集进行排序,需要在第一个select之前和最后一个select的末尾放上括号,然后在结束后放上order by语句

但是我不太明白你的问题。您可以选择按$variis排序的方式,但您选择的是该值

更新:


如果没有得到预期的行,则选择可能过于严格。尝试使用LIKE而不是“=”,甚至使用通配符。

这是一个庞大的查询。您是否可以进一步解释一下您的表结构,以及您最终要从数据库中检索什么;然后按状态排序…@josh我正在使用help_box.status进行排序,只显示状态等于需要帮助的结果…@dagon我已经尝试过了。不起作用。这是对联合进行排序的正确语法。发布您想要的内容,您会看到$variis equals需要帮助,所以我只希望那些显示需要帮助的结果不显示任何其他内容。所以您希望选择$variis,而不是按其排序。它应该与每个select中的where子句一起使用。你得到了什么?