Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How would you do these?


  • Please log in to reply
9 replies to this topic

#1 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 10 January 2009 - 08:04 PM

I am working on my first fully complete website now, I will show once I am done. But I am building it for my brother really but we are sticking up to the local council.

I need a comment box made to articles, news articles. So there will be an article with a page like this;
Mytest.com

That will show the first article, then change the a to 2 it will show the second article. How would I do that?

Now with the comment box, I am thinking of three ways to do it. I don't know which one to choose. Use a SQL database to hold the comments and the names of the people posting. Another way I was thinking of was put it in a text file and read them out of the text file and print them. They are the two most common, but another way I was thinking was an XML file. Since XML would be quite easy I could have my own tags like.
<comment>
 <id>1</id>
 <name>Brandon W</name>
 <date>12 January 2009</date>
 <msg>This is where the message will be.</msg>
</comment>
Get PHP to read each and put them in an array.
[comment][1][id]
[comment][1][name]
[comment][1][date]
[comment][1][msg]
[comment][2][id]
[comment][2][name]
[comment][2][date]
[comment][2][msg]

What do you reckon would be the best method and how would you do it?

Thanks for the help. I have only ever made small scripts for testing my learning on PHP never for a site.
  • 0
I've returned...

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 10 January 2009 - 09:22 PM

If you have database access, use mysql. It will outperform any other method since this is what it is designed for. If you do not have database access, your XML method would be the second best.
  • 0

#3 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 11 January 2009 - 05:07 AM

I was thinking after I made the post that SQL would be the fastest way possible which is what I am after.

How about the news article question? I was thinking of setting up a switch statement somehow.
  • 0
I've returned...

#4 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 11 January 2009 - 06:14 AM

I don't understand your News Article Question. Can you elaborate a bit more?
  • 0

#5 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 11 January 2009 - 06:45 AM

a is a GET request, so simply use that to construct your sql query.

$result = mysql_query("SELECT * FROM `news_table` WHERE `id` = ".mysql_real_escape_string($_GET['a']."");

  • 0

#6 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 11 January 2009 - 04:15 PM

I know it's a GET request, but that's as much as I know. I don't understand how that SQL query would work with a link?

Let's say, visit an IPB forum. And there's would be
www.domain.com/index.php?showtopic=73452

Regarding that SQL query aswell, is each article stored in a table called news_table? Each with it's own unique ID which is then referred to in the link?
  • 0
I've returned...

#7 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 11 January 2009 - 05:21 PM

Regarding that SQL query aswell, is each article stored in a table called news_table? Each with it's own unique ID which is then referred to in the link?


Exactly.
  • 0

#8 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 12 January 2009 - 12:39 AM

Great :) Thanks mate.

So to make sure I get this right.

I make a "news_table" with 4 columns. First being the ID, the date, then the poster and finally the news post.

Now with those, I run a query to return each of them in a row. After, I store the returned results in a variable I will then be able to use $GET in the link?

I don't really understand, could you please show a quick example of some kind?
  • 0
I've returned...

#9 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 12 January 2009 - 09:04 AM

I make a "news_table" with 4 columns. First being the ID, the date, then the poster and finally the news post.

Yes. Your ID will be the unique, primary key and set to auto increment.

Now with those, I run a query to return each of them in a row. After, I store the returned results in a variable I will then be able to use $GET in the link?


No. You run a query to return a specific row. There is no reason to return every row when you only want one. As I showed before:

$result = mysql_query("SELECT * FROM `news_table` WHERE `id` = ".mysql_real_escape_string($_GET['a'])."");


What that is saying is: "select the id, date, poster, and news from the table news_table where the id is equal to $a"
  • 0

#10 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 12 January 2009 - 02:07 PM

Oh I think I got that. But where would I run that query? On the homepage?
  • 0
I've returned...




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download