New to all this

Codes here !

Moderators: egami, macek, gesf

Post Reply
ccordner
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Mar 23, 2017 1:00 pm

Thu Mar 23, 2017 1:08 pm

Good evening

I'm new to all this and I am trying to experiment a little. What I want to do is produce a web page that displays a service status, and another webpage so that people can update it.

At the moment I've got the following code (from w3schools.com):

Code: Select all

			// Create connection
			$conn = new mysqli($servername, $username, $password, $dbname);

			// Check connection
			if ($conn->connect_error) {
				die("Connection failed: " . $conn->connect_error);
			} 
			echo "Connected successfully chris";
		
			$sql = "SELECT colour, status, backcolour, fontcolour FROM DefconRange WHERE active = 'true'";
			$result = $conn->query($sql);
			
			if ($result->num_rows > 0) {
				// output data of each row
				while($row = $result->fetch_assoc()) {
					echo "id: " . $row["status"]. " - Name: " . $row["colour"]. " " . $row["backcolour"]. "<br>";
				}
			} else {
				echo "0 results";
			}
			$conn->close();
			
		?>
I have a few questions:

1. If I know there is only one result, do I need to loop through all the results as above, or is there an easy way of just using the values?
2. If the value for 'backcolour' contains a hex value, can I use the result in a html tag (i.e. font colour or background colour)?
3. Is it possible in MySQL to create a query table (like in Access), because I want the service status to be public.
4. At the moment I've still got the password hard-coded into the page, is there a way to ask the user for a password?

Thanks
Chris

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 502
Joined: Mon Feb 22, 2016 5:52 pm

Thu Mar 23, 2017 2:08 pm

1. If I know there is only one result, do I need to loop through all the results as above, or is there an easy way of just using the values?
No you don't need to loop, when there is only one result - what you have is a generic script so you'll need to modify it to your specific requirements.
2. If the value for 'backcolour' contains a hex value, can I use the result in a html tag (i.e. font colour or background colour)?
Use css and set a class in the html tag to change the colours, it is far easier to maintain the scripts.
3. Is it possible in MySQL to create a query table (like in Access), because I want the service status to be public.
My memory of access has faded, if you mean where there are several drop down boxes where you select the components of a query, then yes this can be done using a html form (although you will need to create the form processing probably using javascript as well as php.)
4. At the moment I've still got the password hard-coded into the page, is there a way to ask the user for a password?
Yes, create a logging in system.

There's quite a lot to learn with no shortcuts; unless you employ someone (and even then you may have problems); the pay off is that you will be able to do exactly what you want to do and how you want to do it so don;t get put off:)

Post Reply