473,386 Members | 1,679 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,386 software developers and data experts.

How to show different content on the page, depending on selected id of article?

ilya Kraft
134 100+
Hello,

I have a database with table that contains articles, article titles, authors of article and id of article etc. I can display all of the articles on my homepage.php But I came over following problem. Say I want to display 1 article on a different page, lets call it article.php, on my homepage.php I will have link below each article that brings user to article.php page. But I want to display different content on article.php depending on selected article so on id of selected article. So say a user clicks a link like this:(which is on homepage.php)
Expand|Select|Wrap|Line Numbers
  1. <a href="article.php?id=1">View this article</a>
  2.  
Now I need to display title,article,author of article with id 1 on articles.php page. This is the problem, how do I find out when to show info of article with id 1, 2 or 3 etc...? I mean how can I know what information to display on article.php page?
Jun 21 '11 #1
4 3288
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. SELECT article, article_title, author
  2. FROM database_table_that_contains_article
  3. WHERE article_id = 1
Unless I have completely misunderstood
Jun 22 '11 #2
nathj
938 Expert 512MB
The article id you are passing in your example URL can be accessed:
Expand|Select|Wrap|Line Numbers
  1. $article = $_GET['id']; // need to error check this first and stripslash at the very least.
  2.  
You can then use the variable in your SQL query as code green says.

Cheers
nathj
Jun 22 '11 #3
ilya Kraft
134 100+
Hi,

Thnx for posts guys ))) nathj, will
Expand|Select|Wrap|Line Numbers
  1. $article = $_GET['id'];
  2.  
collect id from here >> articles.php?id=1 ?
So I can than use something like code green mentioned to collect data from database.
Expand|Select|Wrap|Line Numbers
  1. SELECT article, article_title, author
  2. FROM database_table_that_contains_article
  3. WHERE article_id = $article
  4.  
Am I right? Thnx again )))
Jun 22 '11 #4
Ilya,

Yes, what you posted is correct.

Just to pick up on what NathJ mentioned in his php comment, you are causing a serious issue by doing what you posted. Make sure you read up about 'SQL Injection' which is what you are making possible.

At the very least, you need to ensure that the ID that is given is actually an integer value, eg...

Expand|Select|Wrap|Line Numbers
  1. $article = (int)$_GET['id'];
Jun 23 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: pargat.singh | last post by:
Hi : I am using Master/Child page in VS2005 and i wrote generic function to show/hide controls which works fine if i don't use master/child .Below is my function which work fine for single page...
2
by: SR | last post by:
I have started a web site using ASP.NET 2.0. I would like to centralize all of my classes in a StyleSheet but I cannot figure out how to link the StyleSheet to a Content Page since there is no...
4
by: Mori | last post by:
I am using masterPage and I need to populate a textbox that is in a content control with data from popup page that is not part of the master page. This code works if no masterpage is involved. ...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
2
by: Stanley Omega | last post by:
Hi there, I have created a master page using vs.net 2005. Now I try to add new item > content page and the template is not listed? Any ideas? Steve
2
by: BillE | last post by:
I am using master/content pages, with a treeview in my master page. When the selected node changed event fires in the treeview, I redirect to the requested content page associated with the...
1
by: sudip2008 | last post by:
When using the Calendar Popup in a content page of a masterpage the strForName is always set to aspnetForm This breaks this line from working properly window.opener.document.forms...... How can...
2
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
is there a way to turn off a master page under some conditions? I have a master that has a master page. if a person is a member i wand to show the second level master else i want to hise it. Is...
1
by: redgoals | last post by:
Hi All, I will be creating a white label website for car hire dealers. My main website will be called something like: carhire.com, the content on carhire.com will be pulled in from a database. ...
3
by: sweetneel | last post by:
hi all, thanks in advance. I need a help , its urgent. I am developing a webapplication with maser page. there i have a lebel, control. i need to update its value from the content page, and only...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.