It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

What's the best way to go about this?

Moderator: Malcolm

What's the best way to go about this?

Postby dflynn on Fri Dec 19, 2008 9:53 pm

Alright, so I've hit a brick wall in my programming skills.

My idea is for users to be able to submit content to my site, the content is stored in a database, and then it will be viewable.

I can manage to make a form to submit the Title, Content, Sections it should fall under, and submit each item of the form to a row in the table.
The user would fill out this form and hit submit. Assuming everything passes, it gets put into the database.

Right now, when I access a database to retrieve info my site navigates to the page using ?page=_____
So it's getting a file from an inc/ directory that is essentially just PHP tags telling the page to grab what it needs from the database.

So, if a user submits an article, i should have to create a file within a directory, say, called articles, that could grab the info from the db on it's own, right?

So let's say I submit an article and it it's the 1045th article. so in the database, the id of the article is 1045. Can I get PHP to create a file called 1045.php in the articles folder, and have
Code: Select all
<?php
if (isset($_G ET['page'])) {
   $page = $_G ET['page'];
....whatever else code I need to get the info from the database based on the id....
?>

inserted automatically?

this is the only system I can think up.

If you have any suggestions let me know. Right now my mind is boggled and I feel like I'm talking myself in circles.

Thanks for all your help :)
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: What's the best way to go about this?

Postby flabbyrabbit on Fri Dec 19, 2008 11:41 pm

If everything is stored in the database why not just have one file...e.g. view.php and then use view.php?id=1045. The on page view.php have:
Code: Select all
$id = $ _get[id];
//Select info from databse using $id

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Re: What's the best way to go about this?

Postby dflynn on Sat Dec 20, 2008 12:24 am

ok, thanks for the quick response. I'll build that in tonight and see if I run into any more issues. :D
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: What's the best way to go about this?

Postby dflynn on Sat Dec 20, 2008 2:12 am

aha! it is working like a charm.
:D:D:D
Thanks for all your help so far Flabbyrabbit, I'm sure it can get annoying at times but it's really paying off right now
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: What's the best way to go about this?

Postby dflynn on Sat Dec 20, 2008 8:03 am

Alright, so I am back with this code:
Code: Select all
<?php
      if (isset($_ GET['page'])) {
        $page = ($_ GET['page']);
        @ include "inc/" . $page . ".php";}
        
        else{
        $query = "SELECT cont_id, cont_title, cont_sec, cont_sec2 FROM article";
        $result= mysql_query($query);
        while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
             #variables:
             $id = $row['cont_id'];
             $title = $row['cont_title'];
             $sec = $row['cont_sec'];
             $sec2 = $row['cont_sec2'];

             if ($row['cont_sec']="Photoshop"){
             #echo everything out into a table:
             echo "<tr>";
                if ($sec2="Beginner"){
                echo "<td><a href=view.php?artid=" . $id . ">" . $title . "</a></td>";}
                elseif ($sec2="Intermediate"){
                echo "<td><a href=view.php?artid=" . $id . ">" . $title . "</a></td>";}
                elseif ($sec2="Advanced"){
                echo "<td><a href=view.php?artid=" . $id . ">" . $title . "</a></td>";}
             echo "</tr>";
             
         }}}?>


it checks to see if the $page value has been set, this is so that clicking on the main interface links will override anything else (i'm explaining it weird but it works

then if it $page isn't set it tries to query the DB to get info on all the articles.

I only want articles who's cont_sec value is "Photoshop" so I tired using an if() statement
and then I tried to organize the "Photoshop" articles into three columns based on the cont_sec2 value of "Beginner", "Intermediate", or "Advanced".

Right now it shows three columns with article 1 & article 2 both under Beginner even though Article 2's cont_sec2 value is Intermediate.

Any ideas where I'm going wrong?
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: What's the best way to go about this?

Postby flabbyrabbit on Sat Dec 20, 2008 11:44 am

The easiest way would be to change it in to three separate queries:
Code: Select all
$query = "SELECT cont_id, cont_title, cont_sec, cont_sec2 FROM article WHERE cont_sec = 'Photoshop' AND cont_sec2 = 'Beginner'";
$result= mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
    //echo beginner articles
}
$query = "SELECT cont_id, cont_title, cont_sec, cont_sec2 FROM article WHERE cont_sec = 'Photoshop' AND cont_sec2 = 'Intermediate'";
$result= mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
    //echo intermediate articles
}
$query = "SELECT cont_id, cont_title, cont_sec, cont_sec2 FROM article WHERE cont_sec = 'Photoshop' AND cont_sec2 = 'Advanced'";
$result= mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
    //echo advanced articles
}
That should achieve something like what your looking for.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Re: What's the best way to go about this?

Postby dflynn on Sat Dec 20, 2008 5:55 pm

Ok thanks, I'll implement that today. :D
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: What's the best way to go about this?

Postby dflynn on Sat Dec 20, 2008 9:48 pm

Works like a charm :D
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: What's the best way to go about this?

Postby flabbyrabbit on Sat Dec 20, 2008 10:38 pm

YAY :D
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England


Who is online

Users browsing this forum: No registered users and 1 guest