Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/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在SQL Server中查找与字符串位于同一行的数据_Php_Sql_Sql Server - Fatal编程技术网

PHP在SQL Server中查找与字符串位于同一行的数据

PHP在SQL Server中查找与字符串位于同一行的数据,php,sql,sql-server,Php,Sql,Sql Server,在我的SQL Server中,我有一个名为registration的专栏。在HTML页面中,用户键入注册。然后,当按下submit时,我需要运行我的PHP脚本并获取与输入的注册相同的行中的信息。那么,简单地说,如何搜索列中的值,然后从找到它的行中提取信息?我有 <?php $db = mssql_connect("10.1.173.21", "jsonrequsr", ""); mssql_select_db("rygorWestburySite",$db); $result = mssq

在我的SQL Server中,我有一个名为registration的专栏。在HTML页面中,用户键入注册。然后,当按下submit时,我需要运行我的PHP脚本并获取与输入的注册相同的行中的信息。那么,简单地说,如何搜索列中的值,然后从找到它的行中提取信息?我有

<?php
$db = mssql_connect("10.1.173.21", "jsonrequsr", "");
mssql_select_db("rygorWestburySite",$db);
$result = mssql_query("SELECT Registration, StageOne, StageTwo, StageThree",$db);
$num = mssql_num_rows($result);
$myrow = /* what goes here */;
$i = 1;
if (/* what to put here */) do {
if ($myrow["StageOne"] == "Completed" and $myrow["StageTwo"] == "Incompleted" and $myrow["StageThree"] == "Incompleted") {
    echo "\"itemId\":\"itemid\", \"itemType\":\"JC_AlertView\", \"loadScreenWithItemId\":\"itemid\"";
} elseif ($myrow["StageOne"] == "Completed" and $myrow["StageTwo"] == "Completed" and $myrow["StageThree"] == "Incompleted") {
    echo "\"itemId\":\"itemid\", \"itemType\":\"JC_AlertView\", \"loadScreenWithItemId\":\"itemid\"";
} elseif ($myrow["StageOne"] == "Completed" and $myrow["StageTwo"] == "Completed" and $myrow["StageThree"] == "Completed") {
    echo "\"itemId\":\"itemid\", \"itemType\":\"JC_AlertView\", \"loadScreenWithItemId\":\"itemid\"";
} if ($num > $i) printf(",");
$i++;
} while ($myrow = mssql_fetch_array($result));
else {
echo "Sorry, nothing there to see!";
}
?>

到目前为止,它返回空白。。。根据PHP代码检查器,到目前为止,语法都是正确的

编辑:

好吧,我误解了你的问题。您可以使用SQL查询,使用registration列查找行。也就是说,registration columns值必须是唯一的,以便您只获取一个项目

SELECT * FROM table_name where registration = 'user_input';
预编辑:

如果您在ID列上使用AUTO_INCREMENT进行注册,那么您可以使用来获取插入的最后一个ID,然后根据该ID获取该行,并以这种方式显示数据


此外,您的表应该有一个ID(整数),它是主键,并设置为自动递增。

如果他使用mssql库,我认为该方法不起作用。我需要它,因此它从名为registration的列中获取,而不是ID。而且它也不符合顺序,它将由最终用户输入,记录可以是ID 3或ID 2554。另外,如果您不知道用户输入的是什么,请在SQL中签出运算符。@Michael,这已经完成一半了!现在我需要将在上找到的行存储为变量,这样我就可以运行if($myrow[“StageOne”]=Complete{echo“StageOne”}使用$var=mssql_result($query,0,'StageOne'),如果您知道只返回一行,否则使用for循环并用I替换0。