Good morning everyone,
I could be crazy but I am starting to work more on both my php skills and my mySQL skills, forgive me if I am asking the wrong question in the right forum or vice versa.

My objective
I am building a script so when I log into my backend of my website I can "turn on and off" my website, I was going to accomplish this by building a php script that compared a mySQL table value with either 1 or 0.

So basically:

If table value = 0 the website is offline
else if table value is anything else - include the site

The script

<html>
<body>
<?php 
// Make a MySQL Connection
mysql_connect('localhost', 'myusername', "mypassword") or die(mysql_error());
mysql_select_db('pixelat4_mydatabase') or die(mysql_error());

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM onandoff")
or die(mysql_error());  

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry 

//**this will be where the value is returned from the mysql database**//

if ($row=='0')
	echo 'this will be offline';
else
	include("ms.pk/index.php"); 
?>
</body>
</html>

I am currently using phpmyadmin (have never really used it before), does anybody have some good tutorials that explain indepth how to build a table(yes I have been googling and reading lots but find some of the tutorials to be contradicting and the others don't really explain why I'm doing it).

I did however manage to build a table but its not setup quite the way I think I need it setup for this to work, it has the following columns:
Field Type Collation Attributes Null Default Extra Action

I am asking in the simplest way my brain can think to put it is:
1)I am comparing a row - should I not be comparing to a single field? And if so how do I do so?
2)Is this setup right? Am I on the right track?

I know these are not the most advanced of questions but atleast I am trying!

Nevermind, I got the table thing figured out with phpmyadmin (sorry for the wasted post). For beginners to phpmyadmin, I assumed the top row was the various stuff I had defined in the table row, instead each field I needed was its own separate row. I used insert to add the values I needed until I build the script, now I just need to get my original script working.

Alright so I've gotten it working!

Hopefully I don't confuse anyone.........

I used mysql_fetch_object in my php code to fetch an if function for $row->setting=='my desired value to have the offline' I then echoed "this site is offline".

else

include("subdirectory holding my site").

Now I know somebody who knows the directory that the site sits on can just bypass this first index.php page however it gives it a nice little look with not an overly absorbent amount of code whenever I need to take my website down for maintenance.

Or a simpler way.

create a file index.php, that is your normal home page. Upload it.
create a second one called index.html that contains the just words "site off line"

upload the index.html when the site is off line.
Delete it when it is on line.
no need to touch the index.php, as the index.html will be shown in preference to the index.php whenever it is present.

no need for a database, no need to write code. Just too simple for words.

No I got it all working - and I am going to stick with my complicated method, not because I'm stubborn but because now that I've got one part of code figured out now I want to keep building on it and building on it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.