Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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/8/mysql/64.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 已编辑:通过向文件名添加ID属性来检索表条目?_Php_Mysql - Fatal编程技术网

Php 已编辑:通过向文件名添加ID属性来检索表条目?

Php 已编辑:通过向文件名添加ID属性来检索表条目?,php,mysql,Php,Mysql,我有一个大型的场馆数据库——我想在一个页面中显示这些数据,该页面只会更改id:Ex:vinces.php?id=1的某种属性,该属性将获取第1行的所有数据 编辑:好的,我更新了代码,现在看起来是这样的: <?php mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $id = (int) $_GET['id']; $data =

我有一个大型的场馆数据库——我想在一个页面中显示这些数据,该页面只会更改id:Ex:vinces.php?id=1的某种属性,该属性将获取第1行的所有数据

编辑:好的,我更新了代码,现在看起来是这样的:

<?php 
 mysql_connect("localhost", "", "") or die(mysql_error()); 
 mysql_select_db("") or die(mysql_error()); 

$id = (int) $_GET['id'];
$data = mysql_query("SELECT * FROM venues WHERE id = ".(int)$id) ;

 or die(mysql_error());
 Print "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 Print "<tr>"; 
 Print "<th>Name:</th> <td>".$info['VENUE_NAME'] . "</td> "; 
 Print "<th>Address:</th> <td>".$info['ADDRESS'] . " </td></tr>"; 
 } 
 Print "</table>"; 
 ?> 
在访问Vincements.php?id=1时,我得到以下错误:

分析错误:语法错误,意外的逻辑错误或 /第8行的home/nightl7/public_html/demos/victions/victions.php


你是说:


$id = (int) $_GET['id'];
$data = mysql_query("SELECT * FROM venues WHERE id = ".(int)$id) ;

你是说:


$id = (int) $_GET['id'];
$data = mysql_query("SELECT * FROM venues WHERE id = ".(int)$id) ;

为了将id传递到您的url ventions.php?id=1 您需要使用混合html/php表单和method=get

您可以在此处看到示例html表单:

这就是我要做的:

print '<form name="input" action="venues.php" method="get">';
print 'Venue: <select name = "id">';
$con = mysql_connect("","","");
mysql_select_db($dataBase);
if (!$con){die('Could not connect: ' . mysql_error());}
else {
$opt = array();
$optVal = array();
$i = 0;
$sql = "Select * from venues";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
    $opt[$i] = $row['VenueName'];
    $optVal[$i] = $row['VenueID'];
    print "<option value='$optVal[$i]'>$opt[$i]</option>";
    $i++;
}
}
mysql_close($con);
print '</select><br />';
print '<input type="submit" value="Submit" />';
print '</form>'
这将id号分配给变量$id,然后您可以使用此选择

$data = mysql_query("SELECT * FROM venues WHERE id = ".$id) ;
使用表单中提供的id从数据库中收集场馆名称


祝你好运:

以便将id传递到你的url。php?id=1
<?php 
 mysql_connect("localhost", "", "") or die(mysql_error()); 
 mysql_select_db("") or die(mysql_error()); 

$id = (int) $_GET['id'];
$data = mysql_query("SELECT * FROM venues WHERE id = ".$id) or die(mysql_error());
 Print "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 Print "<tr>"; 
 Print "<th>Name:</th> <td>".$info['VENUE_NAME'] . "</td> "; 
 Print "<th>Address:</th> <td>".$info['ADDRESS'] . " </td></tr>"; 
 } 
 Print "</table>"; 
 ?> 
您需要使用混合html/php表单和method=get

您可以在此处看到示例html表单:

这就是我要做的:

print '<form name="input" action="venues.php" method="get">';
print 'Venue: <select name = "id">';
$con = mysql_connect("","","");
mysql_select_db($dataBase);
if (!$con){die('Could not connect: ' . mysql_error());}
else {
$opt = array();
$optVal = array();
$i = 0;
$sql = "Select * from venues";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
    $opt[$i] = $row['VenueName'];
    $optVal[$i] = $row['VenueID'];
    print "<option value='$optVal[$i]'>$opt[$i]</option>";
    $i++;
}
}
mysql_close($con);
print '</select><br />';
print '<input type="submit" value="Submit" />';
print '</form>'
这将id号分配给变量$id,然后您可以使用此选择

$data = mysql_query("SELECT * FROM venues WHERE id = ".$id) ;
使用表单中提供的id从数据库中收集场馆名称


祝你好运:

我在第8行似乎遇到了一个错误,我用代码更新了我的原始问题以及发生了什么。我在第8行似乎遇到了一个错误,我用代码更新了我的原始问题以及发生了什么。非常感谢Beyerz,我会仔细阅读它,看看我能想出什么-但是有可能从url中获取id吗?原因是我建立了一个表,在onClick上打开一个带有此信息的模式。那么您是否使用表单传递ID,然后在Vincements.php页面上收集ID?不,我使用了我现在拥有的内容,并进行了一些修改。表单是好的,但不是我想在本例中使用的。再次感谢!非常感谢Beyerz,我会仔细阅读它,看看我能想出什么-但是有可能从url获取id吗?原因是我建立了一个表,在onClick上打开一个带有此信息的模式。那么您是否使用表单传递ID,然后在Vincements.php页面上收集ID?不,我使用了我现在拥有的内容,并进行了一些修改。表单是好的,但不是我想在本例中使用的。再次感谢$data=mysql\u querySELECT*来自id=.$id或diemsql\u错误的地点$data=mysql\u querySELECT*来自id=.$id或diemsql\u错误的地点;
<?php 
 mysql_connect("localhost", "", "") or die(mysql_error()); 
 mysql_select_db("") or die(mysql_error()); 

$id = (int) $_GET['id'];
$data = mysql_query("SELECT * FROM venues WHERE id = ".$id) or die(mysql_error());
 Print "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 Print "<tr>"; 
 Print "<th>Name:</th> <td>".$info['VENUE_NAME'] . "</td> "; 
 Print "<th>Address:</th> <td>".$info['ADDRESS'] . " </td></tr>"; 
 } 
 Print "</table>"; 
 ?>