我希望通过 URL 解析一些数据库信息。我不确定具体该怎么做。
页面底部列出的每个事件条目都应包含一个
超链接会将管理员带到一个新的 Web 表单以记录该事件的结果。这
EventID 通过查询字符串参数传递,例如RecordResults.php?EventID=4
。
我究竟该怎么做呢?
感谢您的帮助! 干杯
最佳答案
在 RecordResults.php 中尝试这样的事情:
// Get id from URL
$id = mysql_real_escape_string( $_GET['EventID'] );
// If id is number
if( (int)$id == $id && (int)$id > 0 ) {
// Database connection and select database
$link = mysql_connect('localhost','db_username','db_password')
mysql_select_db('db_name', $link);
// Get record from database
$sql = 'SELECT * FROM tablename WHERE EventID=' . $id;
$result = mysql_query( $sql, $link );
$row = mysql_fetch_array( $result );
// Show record with HTML here
print_r( $row );
} else {
echo "Record not found";
}
关于php - 数据库查询字符串 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10685727/