Current location: Hot Scripts Forums » Programming Languages » PHP » Page ID for news articles...


Page ID for news articles...

Reply
  #1 (permalink)  
Old 06-29-03, 01:57 PM
macj1326 macj1326 is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Page ID for news articles...

You know how some sites have page ids for there news and articles and stuff? Well, I want to know how to do that for one of my news articles so that I don't have to make a new page for each news article. You know, like whatever.php?article=230 and it will go to the news article 230.
Reply With Quote
  #2 (permalink)  
Old 06-29-03, 02:41 PM
Ryan's Avatar
Ryan Ryan is offline
Coding Addict
 
Join Date: May 2003
Location: Virginia
Posts: 391
Thanks: 0
Thanked 8 Times in 3 Posts
There are several ways of doing this. Are you using a database to pull the articles from?
__________________
Ryan Huff
iNET Interactive, LLC

http://www.inetinteractive.com
Reply With Quote
  #3 (permalink)  
Old 06-29-03, 03:34 PM
macj1326 macj1326 is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
That's what I'd like to do. How do I do this?
Reply With Quote
  #4 (permalink)  
Old 06-29-03, 03:44 PM
Ryan's Avatar
Ryan Ryan is offline
Coding Addict
 
Join Date: May 2003
Location: Virginia
Posts: 391
Thanks: 0
Thanked 8 Times in 3 Posts
If you're using a database you'll need to write a script that stores the articles in the database and then calls them out. I'll write something up and post it a little later.
__________________
Ryan Huff
iNET Interactive, LLC

http://www.inetinteractive.com
Reply With Quote
  #5 (permalink)  
Old 06-30-03, 03:23 AM
gizmoitus's Avatar
gizmoitus gizmoitus is offline
Niamh's Daddy
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Whenever I see these types of questions, the first thing I can think to say is: you need to learn something about relational database design, and of course the language to manipulate them which is SQL.

A news app is fairly simple in the way you describe it, and would make for a good learning project. Browse the phpfreaks.com tutorials, they might have a how-to on that.
Reply With Quote
  #6 (permalink)  
Old 06-30-03, 04:22 AM
Stefan's Avatar
Stefan Stefan is offline
Junior Code Guru
 
Join Date: Jun 2003
Location: Utrecht, The Netherlands
Posts: 599
Thanks: 0
Thanked 0 Times in 0 Posts
I second gizmoitus' words. a news script is a very basic script, and is a good way of learning how to do things. besides phpfreaks.com, there are so many other sites outthere that offer tutorials on how to do this. go read em and try it yourself. if you have specific problems, ask questions about that but try to solve it yourself first. thats the best way of learning things.
Reply With Quote
  #7 (permalink)  
Old 07-01-03, 02:02 AM
Ryan's Avatar
Ryan Ryan is offline
Coding Addict
 
Join Date: May 2003
Location: Virginia
Posts: 391
Thanks: 0
Thanked 8 Times in 3 Posts
I'm sorry this took me so long to get back with you, been busy. Here's what I did and I've explained it along the way. This should work, but if you have any problems then let me know.
PHP Code:

<?php


// Connect to the database and select which database we want to use first.

$db mysql_connect("server""username""password") or die(mysql_error());
mysql_select_db("dbname"$db) or die(mysql_error());

// Now we're going to make a query to the database to retrieve all the information we need.

$get mysql_query("SELECT * FROM tbl_name") or die(mysql_error());

// Now we're going to create a loop that will display all the articles for you to choose from.
while($row mysql_fetch_array($get))
{
    
// Declare your variables in here
    
$id $row['ID'];
    
$title $row['title'];
    
$article $row['article'];
    
    echo(
"<a href='http://www.yoursite.com/articles.php?articleid=$id'>$title</a>");
}

if(
$_GET['articleid'] == $id)
{
     echo(
"<b>$title</b><br />");
     echo(
$article);
}
?>
Let me know how it works.
__________________
Ryan Huff
iNET Interactive, LLC

http://www.inetinteractive.com
Reply With Quote
  #8 (permalink)  
Old 07-01-03, 02:13 AM
macj1326 macj1326 is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
I'm sorry to bother you anymore, but what tables should I create in mySQL? Im not too good with mySQL...

EDIT: Nevermind I got it working

Last edited by macj1326; 07-01-03 at 02:25 AM.
Reply With Quote
  #9 (permalink)  
Old 07-01-03, 03:05 AM
Ryan's Avatar
Ryan Ryan is offline
Coding Addict
 
Join Date: May 2003
Location: Virginia
Posts: 391
Thanks: 0
Thanked 8 Times in 3 Posts
Glad to hear it. Let me know if you need anything else.
__________________
Ryan Huff
iNET Interactive, LLC

http://www.inetinteractive.com
Reply With Quote
  #10 (permalink)  
Old 07-01-03, 12:39 PM
macj1326 macj1326 is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Well, I've been tweaking it all morning and I can't seem to get it to stop displaying the link on the top of the page and on the bottom. Heres the code I have:

PHP Code:

<?php 


// Connect to the database and select which database we want to use first. 

$db mysql_connect("localhost""sn""pw") or die(mysql_error()); 
mysql_select_db("db"$db) or die(mysql_error()); 

// Now we're going to make a query to the database to retrieve all the information we need. 

$get mysql_query("SELECT * FROM article_news ORDER BY id DESC") or die(mysql_error()); 

// Now we're going to create a loop that will display all the articles for you to choose from. 
while($row mysql_fetch_array($get)) 

// Declare your variables in here 
$id $row['ID']; 
$date $row['date']; 
$title $row['title']; 
$article $row['article']; 



if(
$_GET['article'] == $id

echo(
"<b>$title</b><br />");
echo(
"<b>Posted on:</b> $date<br /><br />"); 
echo(
$article); 
echo(
"<br><br><br><hr width=\"55%\" align=left><b><u>Other news articles:</u></b><br>");

echo(
"<a href='http://www.gameraddictions.net/news.php?article=$id'><b>$title</b></a> posted on $date<br>"); 

?>
The example of what I'm talking about is http://www.gameraddictions.net/news.php?article=2 ... If I go to the news feed about Tomb Raider then the link to the other one doesn't show up so why does it on this page? How can I stop this? I need it to look like http://www.gameraddictions.net/news.php?article=3 ..... all links on the bottom...

Last edited by macj1326; 07-01-03 at 03:57 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a php registration page codeguru21 Script Requests 3 11-07-03 01:02 PM
need to make a confirmation page codeguru21 PHP 1 10-02-03 04:18 PM
swf music player for web page? xxrockstarxx_1 Script Requests 2 09-13-03 05:10 PM
page navigation help grafik ASP 1 07-27-03 02:08 PM
preload an asp page Gurrutello ASP 1 06-24-03 08:12 PM


All times are GMT -5. The time now is 08:47 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.