Page 1 of 1
$_GET[id]
Posted: Wed Feb 15, 2006 12:14 pm
by Qaid
Hi,
When you browse my website I liked to have this while browsing domain.com/index.php?id=1
When accessing id?=1 it will give me the url from the table ‘2k5’ defined by the id. So when the page has generated I can just use this <? echo $print_id ?> to display the url for id?=1.
This is my code so far…
Code: Select all
$connection = mysql_pconnect("$host","$username","$password") or die ("Error Connecting the Database ".mysql_error."");
$db = mysql_select_db("$database", $connection) or die("Could not select the SQL Database.");
//connects to database
$result = mysql_query("SELECT url FROM 2k5 WHERE id='$_GET[id]'");
if (!$result) {
die('Error:' . mysql_error());
}
while ($result=mysql_fetch_array($result)){
$print_id = $result[????];
}
Can anyone please give me some advice? Please note that im not a hardcore coder!
Thanks..
Posted: Wed Feb 15, 2006 12:23 pm
by a94060
well,to use the $print_id,you would first have to set up the variable as a value( like $_GET['variable']) You would then need to use
echo '$print_id';
Posted: Wed Feb 15, 2006 12:24 pm
by Qaid
Please, can you make a little code for me, I've had looked at this code for some while, and now im really sick and tired of it, if you now what i mean?

Posted: Wed Feb 15, 2006 12:27 pm
by josh
Code: Select all
// you don't need double quotes to expand variables, also mysql_error is a function so it needs to be mysql_error()
$connection = mysql_pconnect($host,$username,$password) or die ("Error Connecting the Database ".mysql_error());
// You do not need quotes on the variable again
$db = mysql_select_db($database, $connection) or die("Could not select the SQL Database.");
//connects to database
// You need to do it like this:
$result = mysql_query('SELECT url FROM 2k5 WHERE id=\''.(int)$_GET['id'].'\' limit 1');
if (!$result) {
die('Error:' . mysql_error());
}
while ($result=mysql_fetch_array($result)){
$print_id = $result[????];
}
Please use [ph
p] tags from now on
Posted: Wed Feb 15, 2006 12:27 pm
by a94060
ill respond later,ciz im in the skool
Posted: Wed Feb 15, 2006 1:17 pm
by Qaid
jshpro2 wrote:Code: Select all
// you don't need double quotes to expand variables, also mysql_error is a function so it needs to be mysql_error()
$connection = mysql_pconnect($host,$username,$password) or die ("Error Connecting the Database ".mysql_error());
// You do not need quotes on the variable again
$db = mysql_select_db($database, $connection) or die("Could not select the SQL Database.");
//connects to database
// You need to do it like this:
$result = mysql_query('SELECT url FROM 2k5 WHERE id=\''.(int)$_GET['id'].'\' limit 1');
if (!$result) {
die('Error:' . mysql_error());
}
while ($result=mysql_fetch_array($result)){
$print_id = $result[????];
}
Please use [ph
p] tags from now on
Sorry about the
Code: Select all
,
What should be in this $result[????]
Just ????
Thanks..
Posted: Wed Feb 15, 2006 1:24 pm
by feyd
$result['url'] which is the only field you're selecting...
You may want to know about
var_export(),
var_dump() and
print_r()
Posted: Wed Feb 15, 2006 1:51 pm
by Qaid
The last question in this topic..
I'll get this warning:
Code: Select all
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /path/to/file/ on line xx
Thanks everyone for the quick answers.
Posted: Wed Feb 15, 2006 1:53 pm
by feyd
mysql_error() will tell you what is wrong with your query.