1

I have a search engine and im trying to open every result in a new window and am not sure what would be the best way to do it. on my search result page "search.php" I am using

$go = "go.php?url=";
print "<a href='".$go."".($row['id'])."' title='".($row['title'])."' rel='nofollow' target='_blank'>".html_entity_decode($row['title'])."</a>";

which would take you to a page like http://website.com/go.php?url=37290

37290 would be the row id and now I have to query it so I can get all the rest of the info and I am having trouble. I know this is really easy but any help would be much appreciated.

on go.php I am using this right now just to show that im grabbing the id from url=37290

<?php print $_GET['url']?>

which obviously prints out 37290 but now I need to query that id in the db and fetch the extra db info.

I need to fetch link_id, title, and url

What would be a good way to do this? Thanks.

EDIT: i would need a query like

select link_id, title, url from search1_links

I hope that shows my db structure better. The db is name is data1

I assuming I need something like

if ($_GET['url']){

sql query stuff here. }

EDIT:

My main problem is I cannot figure out how to make a query with $_GET['url'] url is the id I can do the sql I just need to know how to make a query with the id $_GET['url'] gives me.

5
  • Please share your db structure so we know what "link_id", "title" etc means. Commented Feb 26, 2011 at 23:26
  • Is link_id the same than the id which is in the url ? Commented Feb 26, 2011 at 23:32
  • yes, all the info i seek is in the same row. sory readi ti wrong, but yes link_id is what is in the url. Commented Feb 26, 2011 at 23:33
  • What exactly are you having problems with, the sql statement? Commented Feb 26, 2011 at 23:37
  • yes the sql statement is what i am having trouble with Commented Feb 26, 2011 at 23:43

2 Answers 2

1

Based on your comments, I would do something like:

$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
}

Although I really would use PDO, but that´s another story.

Sign up to request clarification or add additional context in comments.

Comments

0
//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]";

2 Comments

What an odd way to create a query
You're going to have to be waaay more specific.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.