473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Passing database info into URL

Hi,

I have been scouring the Internet for a good read on creating webpages
whose address depends on data retrieved from a from via GET method OR a
MySQL database ... but counldn't find anything decent.

For example, want to create ten pages about 10 different items.
Because I want the header, the footer, the navigation to remain the
same from page to page, I'd like each page to NOT be a separate html
file, but be referenced by something like
http://<mysitename>/items/index.php?item_ID=1. Kind of like separate
WordPress posts.

How would I do something like that and where would I read about it?

Thanks.

Apr 13 '06 #1
7 1600
This is basic php stuff:

header()
switch($_POST['item_ID'])
{
case 1:
includefile('somecontent.php');
break
/* ... others here .. */
default:
includefile('indexcontent.php');

}
footer()

Apr 13 '06 #2
ma*******@gmail.com wrote:
Hi,

I have been scouring the Internet for a good read on creating webpages
whose address depends on data retrieved from a from via GET method OR a
MySQL database ... but counldn't find anything decent.

For example, want to create ten pages about 10 different items.
Because I want the header, the footer, the navigation to remain the
same from page to page, I'd like each page to NOT be a separate html
file, but be referenced by something like
http://<mysitename>/items/index.php?item_ID=1. Kind of like separate
WordPress posts.

How would I do something like that and where would I read about it?

Thanks.


Not too hard - basically, you have a structure similar to:

Code to fetch data from database based on the id
Page header information
Generated data from the database
Page footer information

The reason the code is at the start is often times you might want to change the
<title> contents to reflect the item being retrieved.

As for examples - they're all over the net. Basically anything which uses a
database for the back end does it.

Of course, if the list of items is fixed, you can create 10 pages for them, but
use one header and one footer file, including them in each of the other 10
files. That way you have common headers and footers.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 13 '06 #3
Thanks.

I'll get real specific now. Suppose I have this layout in index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head></head>
<body>
<?php require('includes/header.php');?>
<?php require('includes/navigation.php');?>
<?php require('includes/left.php');?>

... some database retrieval code goes here, e.g. mysql_query ("SELECT
....");

<?php require('includes/centerright.php');?>
<?php require('includes/far_right.php');?>
<?php require('includes/footer.php');?>
</body>
</html>

How would I write the <a href> tags in the 'navigation include file' to
point to individual pages by using the "?id=1" , "?id=2" ... "?id=n"
method in the URL?

Apr 13 '06 #4
On Thu, 2006-04-13 at 06:24 -0700, ma*******@gmail.com wrote:
Thanks.

I'll get real specific now. Suppose I have this layout in index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head></head>
<body>
<?php require('includes/header.php');?>
<?php require('includes/navigation.php');?>
<?php require('includes/left.php');?>

.. some database retrieval code goes here, e.g. mysql_query ("SELECT
...");

<?php require('includes/centerright.php');?>
<?php require('includes/far_right.php');?>
<?php require('includes/footer.php');?>
</body>
</html>

How would I write the <a href> tags in the 'navigation include file' to
point to individual pages by using the "?id=1" , "?id=2" ... "?id=n"
method in the URL?


If navigation.php is going to create links based off of info that you
get from the database, you need to query the database before including
the file.

For example:

<?php
$result = mysql_query("SELECT linkID, linkName from linktable");
require('includes/navigation.php');
?>

navigation.php would then do something like this:

<?php
while($row = mysql_fetch_assoc($result)) {
echo '<a href="yourPage.php?id='.$row['linkID'].'">';
echo $row['linkName'].'</a><br />'."\n";
}
?>

Of course, if navigation.php is the only file using the results from the
database query, you might as well put the query in that file.

Scott

Apr 13 '06 #5
Awesome! Thanks!

What makes the browser display different pages when a new 'linkID' is
called in the address line?

WordPress is a good example ... Specifically what makes WordPress show
different posts when the 'id' is changed in the address line (e.g.
wordpressblog.com/?p=1, wordpressblog.com/?p=2, etc)?

Apr 13 '06 #6
On Thu, 2006-04-13 at 12:32 -0700, ma*******@gmail.com wrote:
Awesome! Thanks!

What makes the browser display different pages when a new 'linkID' is
called in the address line?

WordPress is a good example ... Specifically what makes WordPress show
different posts when the 'id' is changed in the address line (e.g.
wordpressblog.com/?p=1, wordpressblog.com/?p=2, etc)?


Nothing, unless you do something with it through the use of $_GET.

Apr 15 '06 #7
Thanks, guys.

I finally figured it out. If I wrap make my navigation include file
into FORM tags, use METHOD="GET", set up links to point to "?id=n", and
pull the content part out based on query SELECT content WHERE id =
$_GET, then I will get exactly what I was looking for.


Scott wrote:
On Thu, 2006-04-13 at 12:32 -0700, ma*******@gmail.com wrote:
Awesome! Thanks!

What makes the browser display different pages when a new 'linkID' is
called in the address line?

WordPress is a good example ... Specifically what makes WordPress show
different posts when the 'id' is changed in the address line (e.g.
wordpressblog.com/?p=1, wordpressblog.com/?p=2, etc)?


Nothing, unless you do something with it through the use of $_GET.


Apr 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Pacey | last post by:
Hi, I have a web page that gets info from a mySQL database for various items, and slaps that info, along with pics onto the page. ( in a shopping site stylee) The pics have an href link, and I...
6
by: Rob Meade | last post by:
Hi all, At work we have 2 servers in a cluster for our web apps. One problem we have experienced (along with many others!) - is that if a user is logged into one of the applications on server...
6
by: glenn | last post by:
I have a customer class that contains all of my fields and properties related to a single customer. I then have a dataaccess class that knows how to read and write a customer class to and from the...
2
by: lacombpcs | last post by:
I have a web app that searches a database and returns a datagrid table. the user inputs the search terms into a textbox. The user selects the info he wants and it sends him to a 2nd page, after...
2
by: aarnan | last post by:
I have developed a website in ASP.NET 2.0 that is one of several accessed from the same protal. All of the other sites use ASP 3.0, and this is the first .NET site. The rest will be converted as...
7
by: Cordouan | last post by:
I know this looks like it has been answered 1000 times but I have a slightly different problem. I am dealing with forms in order to populate a database. 2 windows : -Main window with my main...
6
by: djjohnst | last post by:
I am creating a program that will list program times for people who visit our website. Users can login create, edit, delete a program. These dump into a database. The ASP webpage then reads from...
3
by: Mufasa | last post by:
Are the only two real options for passing info between pages using QueryString and Session Variables? Am I missing any other viable way? TIA - Jeff.
13
by: frakie | last post by:
Hi 'body, I'm experiencing difficulties on parameter passing. I wrote a library in last months, and now it crashes few times in a month because of errors in parameter passing: using gdb on the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.