Hey guys,

So I'm trying to make a website in php. I'm just wondering, when I click on a link is there any way for the text of the link to be put into a variable. Basically the user will select the name of a database(which is a hyperlink to a menu page), and this will get stored into the database variable to use for the connection.

Thanks in advance for any help :)

Hi,

You mean like this?

link -->link is clicked -> use "link" string as part of the database query -> script returns result based on the query

So, for the above logic the query can be something like this -> select from link, or select from some table where something is equal to link.

Is that it?

If that is what you need you could either grab the link string from the database OR take it from an array. It is reverse of what you have in mind.

Errr... kind of I think.

So the link will be something like "database1" for example. When the user clicks on this link i want it to make a variable storing "database1" so that it can be used in later pages for queries. So in a later page you will be able to view all of the tables that are stored in the database you're on at that time, so it will use the variable in the query for when that page loads, for example.

If that makes any sense?

Thanks for your response :)

Member Avatar for diafol

You probably need a querystring like:

www.mysite.com/page.php?db=database1

You then pick up the db value with

$db = $_GET['db'];

So you'd have your link thus:

<a href="page.php?db=database1">database1</a>

Ah, ok, thank you.

Just wondering, will I then be able to use $db on other pages in the site and it will remember it from that page?

So, the $db=$_GET['db'] will be on a menu page. If I then go onto another page and use $db will it remember the value still? Or do I need to set it as a session variable to work like that?

Thanks for your reply :)

Member Avatar for Zagga

Hi Wolxhound,

It sounds like Sessions could help you out here. It provides an easy way to pass variables between pages.

Member Avatar for diafol

Use sessions as zagga suggests.

Ok, cool :) Thanks guys :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.