从php mysql获取行数据

从php mysql获取行数据,php,mysql,Php,Mysql,我有一个搜索引擎,我试图在一个新窗口中打开每一个结果,但不确定最好的方法是什么。在我的搜索结果页面“search.php”上,我正在使用 $go = "go.php?url="; print "<a href='".$go."".($row['id'])."' title='".($row['title'])."' rel='nofollow' target='_blank'>".html_entity_decode($row['title'])."</a>"; 这里是

我有一个搜索引擎,我试图在一个新窗口中打开每一个结果,但不确定最好的方法是什么。在我的搜索结果页面“search.php”上,我正在使用

$go = "go.php?url=";
print "<a href='".$go."".($row['id'])."' title='".($row['title'])."' rel='nofollow' target='_blank'>".html_entity_decode($row['title'])."</a>";
这里是sql查询。 }

编辑:

我的主要问题是我不知道如何使用$\u GET['url']进行查询 url是id 我可以使用sql,我只需要知道如何使用$u GET['url']给我的id进行查询。

//使用正确的数据库服务器/用户/密码
//use correct db server/user/password
mysql_connect('localhost', 'user', 'pass');
$id = mysql_real_escape_string($_GET['id']);
$result = mysql_query(<<<SQL
   SELECT link_id, title FROM db1.t1 WHERE id = '$id'
SQL
);
$row = mysql_fetch_assoc($result);
echo "$row[link_id] $row[title]";
mysql_connect('localhost','user','pass'); $id=mysql\u real\u escape\u字符串($\u GET['id']); $result=mysql\u查询(
//使用正确的数据库服务器/用户/密码
mysql_connect('localhost','user','pass');
$id=mysql\u real\u escape\u字符串($\u GET['id']);

$result=mysql\u query(根据您的评论,我会这样做:

$id = isset($_GET['url']) ? ((int) $_GET['url']) : NULL;
if (!empty($id))
{
  $sql = "SELECT title FROM some_table WHERE link_id = $id";
  // etc.
}
else
{
  // some error message and exit
}

虽然我真的会用,但那是另一个故事。

根据你的评论,我会做如下事情:

$id = isset($_GET['url']) ? ((int) $_GET['url']) : NULL;
if (!empty($id))
{
  $sql = "SELECT title FROM some_table WHERE link_id = $id";
  // etc.
}
else
{
  // some error message and exit
}

虽然我真的会使用,但那是另一个故事。

请分享您的数据库结构,以便我们知道什么是“链接id”、“标题”etc的意思是。link\u id是否与url中的id相同?是的,我查找的所有信息都在同一行。对不起,读错了,但是link\u id是url中的内容。sql语句究竟有什么问题?是的,sql语句是我遇到的问题。请共享您的数据库结构,以便我们知道什么是“link\u id”,“title”etc的意思是。link_id与url中的id相同吗?是的,我查找的所有信息都在同一行。对不起,我错了,但是link_id是url中的内容。sql语句到底有什么问题?是的,sql语句是我遇到的问题创建查询的奇怪方式你必须是waaay更具体一点。创建查询的方式真奇怪。你必须更具体一点。
$id = isset($_GET['url']) ? ((int) $_GET['url']) : NULL;
if (!empty($id))
{
  $sql = "SELECT title FROM some_table WHERE link_id = $id";
  // etc.
}
else
{
  // some error message and exit
}