- - All
Thread titleFromLast replied
Now searching...
Neoseeker Forums » » Web Coding » [Resource]PHP/MYSQL Tutorials » Post Reply

Note to Guests: For the enjoyment of other visitors, and to help keep this forum tidy and working smoothly, please make sure you search the forum before posting your question.
REPLY TO A THREAD
Name:* Members, please LOGIN before posting
Email: We use this to display your Gravatar

Sign in with
Subject:*
Message:*


HTML is not allowed
markup is allowed

Help with markup tags

Enabling Buttons in IE7




Smilies:
  ·all smilies here
:) :P ;) :( :| ;( :D :confused: :cool: :# :o ^_^ :colored: :thick:

Thread Recap (last 10 posts from newest to oldest)

Aug 15, 03 at 9:55pm
bobbonew


Learning to control the flow of data in php is a must. These if/else/elseif statements control what happens to data and what happens on the page. Here are some examples of these different types of statements-->

For these instructions, the variable $smart=true
<?php
if($smart=='true')
{
print 'Your really smart';
}
?>

That was just a short tidbit of php code that introduced the if statement, a variable, and the print statement. A variable is defined simply as

<?php
$variable= 'text';
?>

The print() function displays the text that comes after it onto the screen. So if I did print 'Hey'; the screen would output Hey. So, for the above flow of text, the logic would simply read, "If the variable smart is equal to true, then output You are really smart". The containers { and } contain what would happen if the instance is true.

The next kind of flow control is the elseif. If the first statement is not true, it would go to the next, and then finally finish-->

<?php
if($smart=='true')
{
print 'You are really smart!';
}
elseif($smart=='false')
{
print 'You are not as smart as I thought';
}
?>

The code above operates as this "If the variable smart is equal to true then print you are really smart. If that is not true, then if smart is equal to false then print you are not as smart as I thought".

The last tidbit of flow control is the else statement. The else statement would happen if all the instances before it have failed. Here is a tidbit of code-->

<?php
if($smart=='false')
{
print 'Your kinda dumb';
}
else
{
print 'I have no idea how smart you are';
?>

Obviously in this instance it would print I have no idea how smart you are becuase $smart does not equal false.

This message was edited by bobbonew on Aug 15 2003.



Aug 15, 03 at 9:03pm
bobbonew


PHP templating system
Level Difficulty:Easy, Required Knowledge oh php: None, MYsql Required: No

What you need-->
  • A server with php installed, almost any version is ok
  • A text editor

    Ok in this short tutorial, you will learn one line of code that can make your website so much easier to template and keep in order. Lets say your website is made of three main parts: a header that is applied to every page, the regular middle content section, and a footer on the bottom of the page.

    If you have a website that contains 4500 pages, it would be take an immense amount of time to update if each page had to have the same header and footer. Well, php is coming to the rescue for you.

    The first step to totally template your site is to first open any page that contains the code to your header and/or footer. Isolate that code and copy/paste that code into your text editor. Now save that file as header.php. Now, do the same thing you did for the header as you did for the footer. Save that file as footer.php.

    Now the next step is to get your main page(s) of your site and delete the header and footer from them. Don't worry, they'll get your amazing complete real soon.

    In place of the header, place the following code:

    <?php
    include 'header.php';
    ?>

    Code Explaination--> <?php is the start of the php code, and ?> is the end of it. include 'header.php'; uses the include() function to call header.php and ; is used to end the statement.

    Woah what did that just do. You just used the php function Include. What it does is parse the header.php page and include the header.php into the page your currently viewing. If you put that code on every page you want a header to be, editing the header.php page would thusly "edit" the other pages making templating easy as pie.
    (You may use the same method you used for the header as the footer)

    Things to watch out for-->
  • Make sure that when you include it is in the correct directory. If you include no /, then the code takes it right from the directory you are in.
  • In your header and footer code, make sure you place your <head> content only in your header.php document. If you have two <head> section, you will get an error saying "Cannot output page, headers already set out on line __"





  • Aug 10, 03 at 1:33pm
    bobbonew


    The first big step in learning php and mysql is connecting to your first mysql database. But before you can connect, you must have a database to connect to! One of the best ways to administrate an online database is through phpmyadmin. I'm going to recommend using this throughout my tutorials as it is the easiest thing to use out there.

    First, log into phpmyadmin and you will get this welcome screen. Type in a name that you want your database to be and click "create".


    Now that you have your first database, you can now set your connection strings in a php file. Open up notepad or any text editor (except Word) and type the following into it:
    code
    <?php
    $conn = mysql_connect("localhost", "username", "password"); 
    $db = mysql_select_db("database_name"); 
    ?>
    

    //Now the things you must obviously substitute in this code is your username, password, and database_name.

    Great you now have the most basic code to connect to your database! Yeah its a great feeling isnt it? It took me about 2.5 hours to connect when I was learning so don't feel bad if you can't get everything to work correctly.

    This message was edited by bobbonew on Aug 10 2003.



    Aug 10, 03 at 2:12am
    bobbonew


    Here is a list that I have found to be the best places on the web for extra help on php and mysql:

  • Php Builder

  • Php Freaks

  • Spoono Tutorials

  • Webmaster World

  • Phpmyadmin

    This message was edited by bobbonew on Aug 10 2003.



  • Aug 10, 03 at 1:52am
    bobbonew


    Index
    Php/mysql Websites
    Connecting and creating your first database
    PHP Templating System
    Different PHP If/Elseif/Else Statements

    Introduction
    PHP is a scripting language that webmasters use to control content on their site from the server side. This means that when you go to view a php page, you would never see any php code, you see the code the server has processed and outputted to you.

    Mysql is perhaps the best online database out there. A database is simple information stored in tables that can be outputted through the use of php. It can store alot of information such as user information, forum posts, news articles, and settings.

    This entire site is based on php and mysql and hopefully at the end of these tutorials, you can design your own content management systema and user base. Plus i'm going to post a few php/mysql goodies for your own site.

    Also, it would help to read the short tutorial by XsLashEr325 to install php on your computer and to learn the basics of php (which I will reinforce).

    [color=#666666]This message was edited by bobbonew on Aug 15 2003.




    Powered by neoforums v1.6.5b (aperture)
    Copyright Neo Era Media, Inc. 1999-2013

    Neoseeker.com   |   Forum Rules   |   Forum FAQ   |   Neoseeker Terms of Use   |   Supermods On Duty [ server id: web2 ··· elapsed: 0.1248650551]
    Chat and Lounges
    Game Platforms
    Mobile Platforms