470,849 Members | 1,155 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

problem with sending value to php page via url - HELP!

Hi!

i have php page that displays records from mysql base.
on that page i have link like this:

<a href="mypage.php?option1">option1</a>

("option1" is name of one of my tables in db)

now i want to load that page and assign this value "option1" as string to
my variable "table".
I tried this:
$table=$_SERVER['QUERY_STRING'];
$query_rs_komp = "SELECT * FROM " . $table;

but it fills my $table var with "database.option1", and i need only
"option1"

Also i'll need help with checking if anything was sent to page anyway - so
if it's first time someone opens page, default value is assigned to var
$table.

please if anyone has idea?
Jul 17 '05 #1
5 1792
ToMeK wrote:
i have php page that displays records from mysql base.
on that page i have link like this:

<a href="mypage.php?option1">option1</a>
<a href="mypage.php?db=option1">option1</a>
("option1" is name of one of my tables in db)

now i want to load that page and assign this value "option1" as string to
my variable "table".
I tried this:
$table=$_SERVER['QUERY_STRING'];
$table = isset($_GET['db']) ? $_GET['db'] : 'default_table';
$query_rs_komp = "SELECT * FROM " . $table;

but it fills my $table var with "database.option1", and i need only
"option1"

Also i'll need help with checking if anything was sent to page anyway - so
if it's first time someone opens page, default value is assigned to var
$table.


HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
In article <2g************@uni-berlin.de>, Pedro Graca wrote:
ToMeK wrote:
i have php page that displays records from mysql base.
on that page i have link like this:

<a href="mypage.php?option1">option1</a>


<a href="mypage.php?db=option1">option1</a>
("option1" is name of one of my tables in db)

now i want to load that page and assign this value "option1" as string to
my variable "table".
I tried this:
$table=$_SERVER['QUERY_STRING'];


$table = isset($_GET['db']) ? $_GET['db'] : 'default_table';


If the man requests page.php?option $_GET will be empty.
But when i test here, $_SERVER['QUERY_STRING'] contains 'option'

With page.php?option=page1 will fill $_GET['option'] with 'page1'
--
http://home.mysth.be/~timvw
Jul 17 '05 #3
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:2g************@uni-berlin.de...
In article <2g************@uni-berlin.de>, Pedro Graca wrote:
ToMeK wrote:
i have php page that displays records from mysql base.
on that page i have link like this:

<a href="mypage.php?option1">option1</a>
<a href="mypage.php?db=option1">option1</a>
("option1" is name of one of my tables in db)

now i want to load that page and assign this value "option1" as string to my variable "table".
I tried this:
$table=$_SERVER['QUERY_STRING'];


$table = isset($_GET['db']) ? $_GET['db'] : 'default_table';


If the man requests page.php?option $_GET will be empty.
But when i test here, $_SERVER['QUERY_STRING'] contains 'option'


thanks it looks like my mistake... wrong table name.
it really contains "option"
- how can i check if there is value in query string, and if there's none,
use default table?

With page.php?option=page1 will fill $_GET['option'] with 'page1'
--
http://home.mysth.be/~timvw

Jul 17 '05 #4
thanks it looks like my mistake... wrong table name.
it really contains "option"
- how can i check if there is value in query string, and if there's none,
use default table?


There are different ways of checking, this just checks to see if there is
any value at all and if not, sets it.

if (!$_SERVER['QUERY_STRING']) { $default_table = "default_value"; }
Jul 17 '05 #5
In article <c7**********@ls219.htnet.hr>, ToMeK wrote:
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:2g************@uni-berlin.de...
In article <2g************@uni-berlin.de>, Pedro Graca wrote:
> ToMeK wrote:
>> i have php page that displays records from mysql base.
>> on that page i have link like this:
>>
>> <a href="mypage.php?option1">option1</a>
>
><a href="mypage.php?db=option1">option1</a>
>
>> ("option1" is name of one of my tables in db)
>>
>> now i want to load that page and assign this value "option1" as string to >> my variable "table".
>> I tried this:
>>
>>
>> $table=$_SERVER['QUERY_STRING'];
>
> $table = isset($_GET['db']) ? $_GET['db'] : 'default_table';


If the man requests page.php?option $_GET will be empty.
But when i test here, $_SERVER['QUERY_STRING'] contains 'option'


thanks it looks like my mistake... wrong table name.
it really contains "option"
- how can i check if there is value in query string, and if there's none,
use default table?


If you looked carefully at the code, you would have noticed that there
was a isset function in use.

--
http://home.mysth.be/~timvw
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by TekWiz | last post: by
6 posts views Thread by Scott Zabolotzky | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.