Database, MySQLl, PHP, site template, blog = Oh GOD!

luca85

New Member
Messages
24
Reaction score
0
Points
0
Well, I've built a website similar to TMZ.com but instead of the news posts there are personal posts like in a blog. Then it hit me that I was going to need a database (new to this) for ease of adding posts, keeping track of them and search option. So I did a little bit of research and ended up installing MySQL, Apache and PHP on my computer. And then everything went blank.

My question is, considering that I already have the website built, how do I add content to my website as posts using PHP, MySQL?

I've created some tables in command prompt trying to understand MySQL, that's as far as I got.

Trying to learn...
 

bidzey75

New Member
Messages
53
Reaction score
0
Points
0
your asking somebody to write you a book, that's a pretty big question...
start here

you'll close in on section 8

it's old 2004, but he explains well, and for now that's important, you can always google other sites if you want more recent.
 
Last edited:

luca85

New Member
Messages
24
Reaction score
0
Points
0
That's what I need, information. Well, I learned how to build websites pretty fast using easier ways than writing code. Hopefully I'll soon find the easier way here as well, like finding on the web the exact PHP scripts that I need for what I'm dealing with.

Thanks for the link.
 

bidzey75

New Member
Messages
53
Reaction score
0
Points
0
well all the luck to you.

If you rely on software to code for you that's ok, but if you never learn what it does and why it's doing it, you'll always be confined to the software your using and trapped in it's box. Iknow there's alot of software out there that will design sites for you without you knowing HTML, but I don't kow of too many that will do that for PHP + MySql. Then again I never really looked for some, so maybe they do exist. Once you get by the logic layer, it get alot easier, and you'll be glad you've decided to go through the learning curve. PHP is not complicated and is a really cool coding language.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
The database sections are dangerously out of date. The old mysql and sqlite extensions shouldn't be used as (among other reasons) they don't support prepared statements, which are extremely important in preventing SQL injection. Those extensions have been supplanted with (most recently) PDO and SQLite3 (which also supports UTF-8 and UTF-16). More troubling, the document doesn't even mention injection. It uses sqlite_escape_string in one script fragment, but never mentions why.

See also "PHP tutorial that is security-, accuracy- and maintainability-conscious?"
 

fretwizz

Member
Messages
106
Reaction score
3
Points
18
That's what I need, information. Well, I learned how to build websites pretty fast using easier ways than writing code. Hopefully I'll soon find the easier way here as well, like finding on the web the exact PHP scripts that I need for what I'm dealing with.

Thanks for the link.

If you find the "the easier way here as well" please let me know;)
 

luca85

New Member
Messages
24
Reaction score
0
Points
0
Hey, well I've been quite busy since I've started this topic and got some basic understanding of CSS, JavaScript, PHP etc to the point where I can write (well, copy paste alter) code, built pages, links, forms etc and having them seen on the web. But, as I'm still a noob in the matter and I would like to shorten the time that it would take to find certain information, maybe someone can help me with a piece of code.

1) While getting intimate, lol, with PHP I found a/some command/code that automatically inserts the contents of a file into an HTML page. Now I was thinking maybe I can use this to update sections of my website just by changing the contents of that file without the use of a database. Does anyone know what's the function that I'm talking about? And if you know, is that a good way to update a section (like blog posts) of a website?

2) Does anyone know the code for arranging text files added to a page by most recent to oldest like in a blog or forum? Hopefully it will be a simple piece of code although I doubt it as I've been looking for something like that for a while now.

Thanks.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
  1. There's readfile to output a file without any additional processing (except for any stream wrappers or filters you explicitly set up). For PHP scripts, there's include/include_once/require/require_once to process the files as PHP. For other scripted pages, there's virtual, which performs an Apache sub-request to fetch the page (note: the result isn't processed as PHP); this function is only available if PHP runs as an Apache module and not a CGI process.

    As for including frequently changing content from another file, it's not much different than editing the file doing the inclusion. If you're using FTP to publish content, then the author needs the same level of access either way. If you're using a web-based editor to edit the file directly, having a separate file can both simplify the editor (as it doesn't need to handle extraneous, write-only portions of the page) and increase security (you don't need to worry about bugs allowing someone to change the write-only sections). On the down side, you need to handle simultaneous edits and all the other stuff that a DBMS does for you.
  2. If you're using the filesystem to store things, you're responsible for fetching and organizing the data. A database, in contrast, can handle much of that for you.

    If you're storing the content in separate files and want to show it in order of file creation or modification,
    • use glob or opendir+readdir to get the list of filenames, then
    • stat to get the time of interest.
    • Store the filename and time in an array of arrays or objects (it doesn't matter which),
    • define a function to compare elements by the time and
    • use usort to sort the array.
    • Loop over the now sorted array, outputting the file content.
    It might look something like:
    PHP:
    <?php
    
    function make_fileinfo($name) {
        $file = new StdClass;
        $file->name = $name;
        $info = stat($name);
        $file->time = $info['mtime'];
    }
    function cmp_mtime($a, $b) {
        # newer times are sorted lower.
        return $b->time - $a->time;
    }
    
    $files = array_map('make_fileinfo', glob('news/*.txt'));
    usort($files, 'cmp_mtime');
    # limit output to 5 items
    $maxPosts = 5;
    ?><ul class="posts"><?php
    foreach (array_slice($files, 0, $maxPosts) as $idx => $file) {
        ?><li><?php
        readfile($file->name);
        ?></li><?php
    }
    ?></ul><?php

    If you want to use some other criteria for sorting the files, you'll have to take care of that as well, by (e.g.) storing the order in another file.
 

bachvtuan88

New Member
Messages
3
Reaction score
0
Points
0
Simple, you can uses some free cms such as wordpress, joomla or tomatocms to build a website.
Otherwise, if you want make a webiste for yourselft, it is depend in yourself.
 

luca85

New Member
Messages
24
Reaction score
0
Points
0
@misson: thanks a lot for the info
@bachvtuan88: I don't want to rely on a cms
 

vv.bbcc19

Community Advocate
Community Support
Messages
1,524
Reaction score
92
Points
48
TMZ.com kind of site can be developed using wordpress and any magazine theme
Example themes are
here

Database etc.. you mentioned are already implemented by wordpress framework.
YOu are to work on your posts..
Correct me if you are of a different opinion.

Well, I've built a website similar to TMZ.com but instead of the news posts there are personal posts like in a blog. Then it hit me that I was going to need a database (new to this) for ease of adding posts, keeping track of them and search option. So I did a little bit of research and ended up installing MySQL, Apache and PHP on my computer. And then everything went blank.

My question is, considering that I already have the website built, how do I add content to my website as posts using PHP, MySQL?

I've created some tables in command prompt trying to understand MySQL, that's as far as I got.

Trying to learn...
 
Last edited:

luca85

New Member
Messages
24
Reaction score
0
Points
0
Yeah, maybe using a CMS is the way to go. I've already tried something called Textpattern but the admin-side was very slow, 2-3 seconds to move from one section to another.
I was leaning towards Wordpress as my second choice but I've noticed that it's not free, you have to pay if you want to use it with a domain like www.example.com. So, if you have some knowledge regarding free CMSs please let me know.
 
Top