Hi everyone, i have been struggling with passing multiple url parameters for quite some time and would be extremely grateful to receive some advice and guidance!

What i ultimately would like to achieve is to pass two parameters in the url, one being the name of a table from a mysql database, and the other being an id. So the url would look like: ...example.com?table=(table name)&id=(id of content). I would like it so that when the name of the table is changed in the url, the content from that table will be displayed. For instance,

...example.com?table=test1&id=1
...example.com?table=test2&id=1

would fetch different data from the two different tables. The reason for this is that i will be using a single template, in which according to the url parameters, will display different information from different tables.

So far i am only able to fetch the id's from one table at a time that i have defined in the query. After what feels like a million attempts for well over a week i am stumped and have gone back to my original code displayed below. Any help with this would be extremely appreciated. Many thanks.

function global_nav() {
	$conn = connect();
	
	$sql = "SELECT * FROM article";
	$result = mysql_query($sql);
	
		if(!$result) 
		{
			echo "DB Error, could not process menu items.<br/>MySQL Error: ".mysql_error();
    		exit;
		}
		while($row=mysql_fetch_array($result)) 
		{
			$id = $row['id'];
			echo '<a class="global" href="article.php?id='.$id.'">'.$row['articleTitle'].'</a>'; // 'articleTitle' being the name of the column in the table.
		}
	closeconnection($conn);
}

I am not sure I understand exactly what you are trying to do here, but surely passing a table name in the URL is a very bad idea.

Isn't the reason that SQL errors should be suppressed in production sites because the developer does not want the table name to be known?

If you can explain a little more what you want to do then I am sure someone will be able to help.

Hi Xan thanks very much for responding. What i have is a small content management system that uses a single html template but pulls different content from the database depending on the url parameters, as they are going to be masked. So far i am only able to pull info from a single table at a time which i define in the query during the function. To best manage the content for different users, i thought it would be best to create a separate table in the database for each user where their content can be stored, hence the need to pull different info from different tables in the url.

However i'm guessing my desired solution to this isn't by passing a table name as a url parameter! I've just come to a bit of a standstill, so far i have a full content management system but only for a single user linked to one table, and i'm not sure how to create one for multiple users without duplicating the files and changing each table name in the code manually for each user.

Problem solved by using a modified preorder tree traversal model, where i can contain multiple user's content by defining nodes to store the data. Thanks to everyone who responded!

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.