PHP, MySQL, etc.

GJSNeptune

[H]F Junkie
Joined
Mar 31, 2004
Messages
12,372
Before I try again to grasp PHP and MySQL, I'd like to be steered in the right direction.

I want to put a bunch of writing into a database and retrieve them like most sites today. I'm assuming there's no need to manually create the page for these, and that PHP generates a page or uses a template to display each writing piece.

What aspect of PHP will I want for this? Basically the user clicks on something to read, and the URL has the usual ?=blahblahblah, and it displays all the text under the stylesheet, etc.

I've also been told it's easier to manually create MySQL tables and such, but programming is quite beyond me and I still haven't wrapped my brain around the whole process yet.

Thanks.
 
have you had any programming before??

I started with some C++ knowledge and that helped a lot.

If you are not familiar with php and/or mysql, it might be easier to work with files for your content.

for example, let's say your file you are working on is show.php and to get your article, you'd do something like: show.php?page=mysql
let's also say that the article you want to display is called mysql.html which is inside the folder "articles".

in your code, you could do an if/else to determine the value of page...however, I'd do a switch/case as it is much easier to code if there gets to be many articles. A great place to look at php examples for if/else and switch/case is www.tizag.com.

anyway, once you have determined the value of "page", php has a function called "include" that will inject a file, as html, into your document. So within the article condition, you can say:
include('articles/mysql.html');
this will inject whatever html into your php file. I use this a lot for my menus, so that they stay the same on all pages and does not use frames or iframes.


I hope this doesn't confuse you, but if it does, go to tizag and lookup if/else, switch/case, and the include function.
 
So on index.php, I have a link to show.php, which loads with a URL of something like show.php?page=article. The article then displays inside whatever div has the include/require PHP command?

So really I just need one page template for displaying content. Right?
 
yeah, you need one template page that will "include" a file based on the variable value. The file included will have your article content.
 
Couple more questions.

Let's say some of the articles in the database are pretty long, and I don't want to display them in their entirety, and instead have them parsed and cut off after so many characters (or a better method?). I always see professional sites that have the ...[more] or something similar at the end of blurbs. How do they do that?

And say I want to have page numbers. How can I get PHP to do all of this automatically? I'm also thinking of displaying page numbers (where applicable) in maybe another div. I dunno yet. I don't want my design to get ahead of my knowledge of possibilities.

I checked out Tizag (I've gone through some of their tutorials before) and even printed out the MySQL stuff. If I can narrow down what commands I need, I'll pick it up much quicker.
 
You could put special characters in the file (might even use the <br> tag, something that wouldn't really be rendered in html, but something to be a delimiter), then use the php function "explode" to separate the file on that character. An indexing variable would be needed to keep track of which "page" of the article to show, which would just be used as the array index number.

When articles paginate, they already start out with multiple records in a database. So it will go either way...if you want pagination, you will either need a database with multiple records...or you will need multiple html files for the articles.

to get page numbers to generate automatically, with files, you can use a function to count the number of files in "/articles/mysql/". By default, you'd start at one and that would be an indexing variable in the php file. In your link for the next page, you could do something like "show.php?article=mysql&p=2"...but that number two would be done automatically by incrementing the index variable. you would also need checks to see if the indexing variable equals the number of files counted...so instead of a "next" link, you could replace it with a "home" link or something.
 
another way would be to get the whole record, and divide the record by a character count. Thats your pages

then do a mid on the whole thing with page number * your character count for character count length and that will give you the text for that 'page'

That way is probably slow, and multiple records in the DB might be faster. I have no clue, as, I have never actually done anything like this.
 
the problem with doing a character count, you run the risk of breaking a word in half...or a paragraph.

I'll see if I can write something up within a few days to get something like this going. it would be a neat little project.
 
My biggest obstacle is dealing with MySQL. I think it's the phpMyAdmin interface. It's all a bunch of boxes and tabs and stuff and it's overwhelming. I've been told that phpMyAdmin sucks and I should use something else, or manually add tables, etc. I don't remember what they recommended.

The PHP I can grasp easier because it's embedded into the XHTML, and I can more easily see what's going on, and I'm much more used to it.
 
phpmyadmin sure beats manually creating the tables though ;)
 
My biggest obstacle is dealing with MySQL. I think it's the phpMyAdmin interface. It's all a bunch of boxes and tabs and stuff and it's overwhelming. I've been told that phpMyAdmin sucks and I should use something else, or manually add tables, etc. I don't remember what they recommended.

The PHP I can grasp easier because it's embedded into the XHTML, and I can more easily see what's going on, and I'm much more used to it.

phpMyAdmin is a great front-end MySQL tool. There are plenty of quick MySQL introductions out there, and trust me, once you grasp the concept of how databases work, you'll see that SQL is the easiest of languages to learn. phpMyAdmin only makes it easier.

If you plan to use PHP/MySQL to store articles and such in a database, you pretty much HAVE to learn some MySQL syntax. I would recommend checking out www.phpfreaks.com, as they have pretty good tutorials and articles for new-comers.
 
Do you have any particular reason for wanting to write blog software from scratch? There's plenty of packages available out there.

It seems like you want a blog, but don't know how to program. If I'm wrong and you want to learn how to program and just picked a blog as your project, then I'm mistaken.

In the case of wanting a blog, I'd just go use some package and be done with it (wordpress or whatever).

If you are wanting to learn how to program, then you should really do some more research and maybe pick up a book or two and actually learn some of the basics before pursuing the design of this system any further.
 
It's not really a blog. I'm going to host a lot of my writing. Poetry, fiction, nonfiction, screenwriting, etc. I like knowing what's going on behind-the-scenes, and being able to say that I built the site and didn't just use Wordpress or something similar.

It isn't going to be that complex. Nothing that'll utilize every or most of what PHP can do. Just pulling text from a database and displaying it.
 
It's not really a blog. I'm going to host a lot of my writing. Poetry, fiction, nonfiction, screenwriting, etc. I like knowing what's going on behind-the-scenes, and being able to say that I built the site and didn't just use Wordpress or something similar.

It isn't going to be that complex. Nothing that'll utilize every or most of what PHP can do. Just pulling text from a database and displaying it.

Here are some things off the top of my head that you should learn how to do when creating something of this sort:

  1. Basic PHP syntax
  2. Basic programming knowledge for logical operations (if then else, etc)
  3. How MySQL databases are constructed into tables, rows, and columns
  4. How to use the built in PHP functions to connect and send queries to a MySQL database
  5. How to read what MySQL returns into variables
  6. How to display variables inside of a PHP/HTML page
 
It's not really a blog. I'm going to host a lot of my writing. Poetry, fiction, nonfiction, screenwriting, etc. I like knowing what's going on behind-the-scenes, and being able to say that I built the site and didn't just use Wordpress or something similar.

It isn't going to be that complex. Nothing that'll utilize every or most of what PHP can do. Just pulling text from a database and displaying it.

judging from the posts so far, it looks like you have very little, if any, programming experience. i don't want to discourage you, but you do realize its going to take several months of fairly intense effort to learn the most basic skill sets needed to tackle something like this.

its not just a matter of learning the syntax of PHP, SQL, etc.. far more importantly, you are going to have to learn programming concepts, database design concepts, and how to design a secure, scalable application. this means being able to look at a problem and break it down into its logical parts, and from those parts, recognize which programmatic approaches are best suited to them, then you write the actual code to make it all happen.

the planning phase for something like this starts with the database design, choosing how many tables you will need and determining how to set up the relationships between those tables.
for example, what will a post to your site consist of? maybe a title, body, date, category? are you going to allow comments on each article? if so, do those need the name, email and website of the poster, a date, etc..? will comments be threaded or flat? etc, etc. etc...none of this even starts to address any SQL syntax knowledge yet, not even mentioning tying it in with your PHP scripts and your html/css templates.
 
so this is only a proof of concept...so there are plenty of bugs...but it does what you want it to do and does it without a database using regular html files

http://files.ccernst.net/examples/show.php

http://files.ccernst.net/examples/showcode.zip

Many thanks, Fark. Good to have some encouraging and supportive people in the thread. People who don't think this is a project much bigger than it is.


For the last time, this isn't a blog. No comment system. No posting. Just me putting stuff in a database and having them retrieved.
 
For the last time, this isn't a blog. No comment system. No posting. Just me putting stuff in a database and having them retrieved.

call it what you will, the principles are exactly the same. If you're going to be putting stuff in a DB (or flat file), pulling it out, sorting it, formatting it and displaying it, you're still going to need to learn the skill sets in order to do it on your own.
 
Well please don't respond to my threads in this subforum. I'd rather have encouragement so that I'll want to make an effort to learn what I need to learn.

I hope you're not a teacher.
 
Well please don't respond to my threads in this subforum. I'd rather have encouragement so that I'll want to make an effort to learn what I need to learn.

I hope you're not a teacher.

suit yourself. i was more than willing to help, like i do quite often in this forum. i just wanted you to have an idea that what you're trying to do is not trivial for someone with little or no experience. it wasn't meant to discourage you, but to help you decide if this is really something you want to pursue.
 
Back
Top