In this code I'm trying to create as many modal boxes as the rows of my query result. This works! Then I want to fill these modal boxes with as many checkboxes as the number $row['seats_no'] from database. Here we have a problem..in every modal box it creates the same amount of checkboxes as the first one. What I mean is that the $row['seats_no'] has the number from the first row in every row.
<?php
session_start();
if(!isset($_SESSION['name']) && !isset($_SESSION['email']) && !isset($_SESSION['id']) && !isset($_SESSION['cash'])){
header("location: Start.php");
}
$name=trim($_SESSION['name']);
$email=trim($_SESSION['email']);
$dbc = mysqli_connect("localhost","root","","my_db");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($dbc,"SET NAMES 'utf8'");
mysqli_query($dbc,"SET CHARACTER SET 'utf8'");
if (isset($_POST['buy']) && isset($_POST['consert_id'])){
$q = "SELECT ticket_id, section, cost, seats_no FROM tickets INNER JOIN concert ON tickets.consert_id=concert.concert_id WHERE concert.concert_id=".$_POST['consert_id'];
//ticket_id, concert_id, section, cost, seats_no, concert_id,concert_name, date, place, category, description
$r = mysqli_query($dbc,$q);
$num= mysqli_num_rows($r);
$q1 = "SELECT * FROM concert WHERE concert_id=".$_POST['consert_id'];
$r1 = mysqli_query($dbc,$q1);
$first = mysqli_fetch_assoc($r1)
?>
<!DOCTYPE html>
<html>
<title>Seats</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link type="text/css" rel="stylesheet" href="seats_style.css">
<body>
<div style="z-index:1;position:fixed;">
<ul>
<li>E-Viva</li>
<li>Ανανεωση υπολοιπου</li>
</ul>
</div>
<div class="background">
<div class="transbox">
<div class="w3-container">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/199011/concert.png">
<h1><?=$first['concert_name']?></h1>
<div style="left:0;"><?=$first['date']?></div>
<div style="right:0;"><?=$first['place']?></div>
<p><?=$first['description']?></p>
<?php
while ($row = mysqli_fetch_array($r)) {
?>
<div style="margin-left:5em;padding:5px;"><?=$row['section']?></div>
<div style="margin-left:5em;padding:5px;">Τιμή <?=$row['cost']?>€</div>
<div style="margin-left:5em;padding:5px;"><button onclick="document.getElementById('id01').style.display='block'" class="w3-button w3-black">Κράτηση</button></div>
<div id="id01" class="w3-modal" background="black">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('id01').style.display='none'" class="w3-button w3-display-topright">×</span>
<p><h2>Διαλεξε τις θεσεις που θες</h2></p>
<form action="buy.php" method="post">
<table>
<?php
$num=0;
for($j=1; $j<=10; $j++){
echo "<tr>";
for($i=1; $i<= $row['seats_no']/10; $i++){
$num++;
echo "<td><input class='seat' type=\"checkbox\" name=\"s[]\" id=\"".$num."\" value=\"".$num."\"><label for=\"".$num."\">".$num."</label><input type='hidden' name='ticket_id' value='".$row['ticket_id']."'><input type='hidden' name='cost' value='".$row['cost']."'></td>";
}
echo "</tr>";
}
echo "</table><input class=\"ok\" type=\"submit\" name=\"ok\" value=\"Κράτηση\"></form></div></div></div><br>";
}
}
mysqli_free_result($r1);
mysqli_free_result($r);
mysqli_close($dbc);
?>
</div>
</div>
</div>
</body>
</html>
here are the results i get from executing my query at phpMyAdmin
Here are the buttons I create to open the modals
And here is the modal from the last button i clicked that in the database shows it should be 60 checkboxes but it shows 180
Κατερίνα,
Try to change the while ($row = mysqli_fetch_array($r)) {...} with a foreach loop,
like as foreach( mysqli_fetch_array($r) as $row ) {....}
Just a thought.
Also, you close one bracket too soon, remove one before the first mysqli_free_result($r1) and close it after the closing html tag </html> at the end of the file.
Also, as #tadman said, do some research and use parameterized queries. Your code it's very prone to MySQL Injections and you will face several problems. As far as i can see that page has to do with payments, or pre-payment.
Anyways, i hope i helped you.
Καλή επιτυχία ;)
Related
Recently I am writing a products catalog for my company. I use the dropdown list to provide a filter to a grid views product list that has pagination. The filter is work fine if products not more than 1 page. When more then one page of search result, the browser will show all products same as no filter applied. Below is my code of the index.php. Please help because I already stuck in here for a week. Thank in advance.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php session_start();
if (!isset($_SESSION['user_name']))
{
echo "<script>window.open('../login.php','_self')</script>";
}
$user_name=isset($_SESSION['user_name'])?$_SESSION['user_name']:'';
?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/gallery.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-3.2.1.min.js"></script>
<meta name="theme-color" content="#444" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<?php
include_once('../database/db_conection.php');//Include the database connection
?>
<div class="container">
<div class="col-md-2"> <br/>
<i class="fa fa-home" style="font-size:28px"></i>Home <br/>
<br/>
<br/>
<form action="buckle.php'" method="post" >
<div class="cf_header5">MATERIAL<br/>
(e.g.Brass, Alloy...)</div>
<select name="material" style="width:150px; height:25px;font-size:16px">
<option value="">Please select ....</option>
';
<?php
$sql_ml = "SELECT distinct material FROM products where material !='' order by material";
$records_ml=mysqli_query($dbcon,$sql_ml);
while ($row_ml=mysqli_fetch_array($records_ml)){
echo '<option value="'.$row_ml['material'].'">'.$row_ml['material'].'</option>';
}
?>
</select>
<br/>
<br/>
<div class="cf_header5">DESCRIPTION</div>
<select name="description" style="width:150px; height:25px;font-size:16px">
<option value="">Please select ....</option>
';
<?php
$sql_dn = "SELECT distinct catagory FROM products where catagory !='' order by catagory";
$records_dn=mysqli_query($dbcon,$sql_dn);
while ($row_dn=mysqli_fetch_array($records_dn)){
echo '<option value="'.$row_dn['catagory'].'">'.$row_dn['catagory'].'</option>';
}
?>
</select>
<br/>
<br/>
<div class="cf_header5">SIZE</div>
<select name="size" style="width:150px; height:25px;font-size:16px">
<option value="">Please select ....</option>
<?php
$sql_se = "SELECT distinct size FROM products where size !='' order by size";
$records_se=mysqli_query($dbcon,$sql_se);
while ($row_se=mysqli_fetch_array($records_se)){
echo '<option value="'.$row_se['size'].'">'.$row_se['size'].'</option>';
}
?>
</select>
<br/>
<br/>
<input type="submit" name="submit" value="Search" />
</form>
<?php //get the value from dropdown list and stored it to a variable
$material=isset($_POST['material']) ? $_POST['material'] : "";
$size=isset($_POST['size']) ? $_POST['size'] : "";
$description=isset($_POST['description']) ? $_POST['description'] : "";
?>
</div>
<div class="col-md-10">
<div id="main">
<header>
<div class="logo-outer">
<div class="logo"> <img src="../images/logo4.png" /> </div>
<?php
//////SET UP THE TOTAL images PER PAGE & CALCULATIONS:
$per_page = 12;// Number of images per page, change for a different number of images per page
// Get the page and offset value:
if (isset($_GET['page'])) {
$page = $_GET['page'] - 1;
$offset = $page * $per_page;
}
else {
$page = 0;
$offset = 0;
}
//Display no of items in cart
echo '<a href="viewcart.php?page=';echo $page+1;echo '&type=buckle';echo'">';
echo "You have";
$t_sql="select count(product_id) as nocart from cart where user_name='$user_name'";
$t_run=mysqli_query($dbcon,$t_sql);
$t_row=mysqli_fetch_array($t_run);
$cart_count=$t_row['nocart'];
echo ' ';
echo '<span class="badge" >';echo $cart_count; echo '</span>';
echo ' items on list</a>';
//end of display number of items in cart
?>
</div>
</div>
</header>
<div class="margin">
<div id="pagination"><!-- #pagination start -->
<?php
$images_sql="select count(id) from products where product_type='buckle'";
if(isset($_POST['material'])and $material!='')
{$images_sql=$images_sql." and material='$material'";}
if(isset($_POST['description'])and $description!='')
{$images_sql=$images_sql." and catagory='$description'";}
if(isset($_POST['size'])and $size!='')
{$images_sql=$images_sql." and size='$size'";}
$images_sql=$images_sql." ORDER by id ASC";
$result_images = mysqli_query($dbcon, $images_sql);
$row_images = mysqli_fetch_array($result_images);
$total_images = $row_images[0];
// Calculate the number of pages:
if ($total_images > $per_page) {//If there is more than one page
$pages_total = ceil($total_images / $per_page);
$page_up = $page + 2;
$page_down = $page;
$display ='';//leave the display variable empty so it doesn't hide anything
}
else {//Else if there is only one page
$pages = 1;
$pages_total = 1;
$display = ' class="display-none"';//class to hide page count and buttons if only one page
}
////// DISPLAY THE PAGE COUNT AND BUTTONS:
echo '<h2'.$display.'>Page '; echo $page + 1 .' of '.$pages_total;//Page out of total pages
$i = 1;//Set the $i counting variable to 1
echo '<div id="pageNav"'.$display.'>';// $display variable will do nothing if more than one page
// Show the page buttons:
if ($page) {
echo '<button><<</button>';//Button for first page [<<]
echo '<button><</button>';//Button for previous page [<]
}
for ($i=1;$i<=$pages_total;$i++) {
if(($i==$page+1)) {
echo '<button class="active">'.$i.'</button>';//Button for active page, underlined using 'active' class
}
//In this next if statement, calculate how many buttonso show.
if(($i!=$page+1)&&($i<=$page+3)&&($i>=$page-1)) {//This is set for two below and two above the current page
echo '<button>'.$i.'</button>'; }
}
if (($page + 1) != $pages_total) {
echo '<button>></button>';//Button for next page [>]
echo '<button>>></button>';//Button for last page [>>]
}
echo '</div>';// #pageNav end
?>
</div>
<div id="gallery"><!-- Gallery start-->
<?php
// DISPLAY THE images:
//Define the SQL statement based on the dropdown list
if ($total_images>0)
{
$img_sql="select * from products where product_type='buckle'";
if(isset($_POST['material'])and $material!='')
{$img_sql=$img_sql." and material='$material'";}
if(isset($_POST['description'])and $description!='')
{$img_sql=$img_sql." and catagory='$description'";}
if(isset($_POST['size'])and $size!='')
{$img_sql=$img_sql." and size='$size'";}
$img_sql=$img_sql." ORDER by id ASC LIMIT $offset, $per_page";
$result = mysqli_query($dbcon, $img_sql);
while($row = mysqli_fetch_array($result)) {//Open the while array loop
//Define the image variable:
$image=$row['images'];
$product_id=$row['product_id'];
$product_type=$row['product_type'];
$size=$row['size'];
$material=$row['material'];
$description=$row['catagory'];
echo '<div class="img-container">';
echo '<div class="img">';
echo '<img src="images/'.$image.'">';
echo '</a>';
echo '</div>';
echo $product_id;echo '    ';
echo 'Add to List';
echo '<br/>Size:';echo $size;
echo '    Material: '; echo $material ;
echo '<br/>Description: ';echo $description;
echo '</div>';// .img-container end
}//Close the while array loop
}
else
{
echo'<br/><br>';
echo '<h1>Sorry! No result is matched, please search again.</h1>';
echo'<br/><br>';
}
?>
</div>
<!-- Gallery end-->
<div class="clearfix"></div>
</div>
</div>
<!-- #main end -->
</div>
</body>
</html>
Your logic seems OK but your problem is when you navigate trough pages you make a new call of the document, which doesn't include variables like filters but the current page ($_GET['page']).
Either you send filters as variables trough URL as well, which isn't the cleanest way to do table pagination.
Or you gather results in a javascript array, and then on click on a pagination button display the previous/next rows. By doing this you also avoid refreshing the whole document every time, which isn't necessary.
Hey there stackoverflow users, i have come upon a very confusing problem that I cant seem to move past. I am creating a forum type web page and am currently working on the comments section. I have a form that uses the post method to send your comment as well as a hidden input to store the threads ID. I will post the entire php file below just to make sure nothing is left out.
<?php
session_start();
parse_str($_SERVER['QUERY_STRING'], $link);
$threadID = $link['ID'];
require("config.php");
$connection = mysqli_connect($host, $user, $password, $database);
$error = mysqli_connect_error();
if($error != null) {
$output = "<p>Unable to connect to database!</p>";
exit($output);
} else {
//Get Thread Data
$query = "SELECT username, title, content FROM threads, users WHERE threads.ID = $threadID AND users.ID = threads.makerID;";
$results = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($results);
//Get Comment Data
$query = "SELECT username, comment FROM comments, users WHERE threadID = $threadID AND users.ID = comments.makerID;";
$results = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($results);
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<title>BodyweightMate</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/styling.css"/>
</head>
<body>
<!--Top masthead-->
<header class="masthead" id="top">
<h1 class="masthead-title"> Welcome To BodyweightMate </h1>
</header>
<!--Navigation bar-->
<nav class="navbar">
<table class="navbar-table">
<tr>
<!--Logo-->
<td>
<a class="navbar-brand" href="main.php">
<img src="../images/logo.jpg" alt="BodyweightMate" height="30" width="30">
</a>
</td>
<!--Login/Profile-->
<?php if(isset($_SESSION['login_user'])) {
echo"<td><a class=\"navbar-profile\" href=\"profile.php\"> Profile </a></td>";
echo"<td><a class=\"navbar-logout\" href=\"logout.php\"> Logout </a></td>";
} else {
echo"<td><a class=\"navbar-login\" href=\"login.php\"> Login </a></td>";
}?>
</tr>
</table>
</nav>
<!--Main portion-->
<section class="content-section">
<article>
<h3><?php echo $row['username']. ": " .$row['title']; ?></h3>
<p><?php echo $row['content']; ?></p>
<br>
<h3>Comments</h3>
<p>Some annoying user: Gr8 B8 M8</p>
<p>Annoying users friend: I R8 8/8</p>
</article>
<div>
<!--If logged in, ability to comment-->
<?php if(isset($_SESSION['login_user'])): ?>
<form role="comment-form" method="POST" action="processcomment.php" id="mainForm">
<input type="hidden" value="$threadID" name="threadID">
<div class="form-group">
<label for="comment">Comment </label> <br>
<textarea class="comment-text" name="comment" rows="2" maxlength="255"></textarea>
</div> <br>
<input type="Submit" class="btn-newcomment" value="Submit Comment" name="submit">
</form>
<?php endif ?>
</div>
</section>
<!--Right portion-->
<aside class="content-aside">
<div>
<!--If logged in, be able to create a thread-->
<?php
if(isset($_SESSION['login_user'])) {
echo"<form method=\"post\" action=\"makethread.php\">";
echo"<input type=\"submit\" class=\"btn-newthread\" value=\"Create New Thread\" name=\"submit\">";
echo"</form>";
}
?>
</div>
<!--Info-->
<div>
<p> GOING TO NEED A SEARCH FUNCTION HERE
This is the cool little aside section. It will always be there to provide you with some very nice little details, helpful links, maybe a list of moderators? who knows! The uses are endless when you have a beautiful little aside like this one! Here are a few very useful bodyweight fitness links to get us started :D </p>
</div>
<br>
<div>
<ul class="content-aside-links">
<li>
Reddit's Bodyweightfitness Forum
</li>
<li>
Reddit's Bodyweightfitness RR
</li>
<li>
Antranik's Bodyweightfitness Routine
</li>
</ul>
</div>
<div></div>
</aside>
<!--Footer -->
<footer class="footer">
<div>
<p> Use of this site constitutes acceptance of our User Agreement © 2017 BodyweightMate inc. All rights reserved. </p>
</div>
</footer>
</body>
</html>
The error is occurring under the main portion where i check if a user is logged in, and if they are add a short form consisting of a message, a text area, and a submit button. This form sends the information to the following php file.
<?php
session_start();
if(!isset($_SESSION['login_user'])) { header("location: main.php"); }
?>
<!DOCTYPE html>
<html>
<body>
<?php
require("config.php");
$connection = mysqli_connect($host, $user, $password, $database);
$error = mysqli_connect_error();
if($error != null) {
$output = "<p>Unable to connect to database!</p>";
exit($output);
} else {
//Validation
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$comment = $_POST['comment'];
$threadID = $_POST['threadID'];
$user = $_SESSION['login_user'];
} else {
//Redirect back to register
echo"<p>Form must use post or input was bypassed.</p>";
echo" Return to home page. ";
mysqli_close($connection);
exit();
}
There is no issue with connecting to the database, and I don't believe the remainder of the code is necessary to help me with this error since that one if statement of checking if the form is using post is failing and the else statement is always called. Why is this? i have rewritten the form multiple times ensuring that its properly structured and using post yet it fails every time!
I am still very new to MySQL/PHP and am trying to make code that will loop through my whole SQL table. I was able to do that, to clean things up I wanted to use an html table to store the values in to make things look neater. I tried adding the HTML code into the string which gets printed at the bottom of the code in the HTML section, but the table borders do not show. What am I doing wrong and how can I fix this? Both code and screenshot of output are below:
<?php
include("connection.php");
$query= "SELECT * FROM schedule";
$result = mysqli_query($link, $query);
$scheduletext="<table>";
if($result = mysqli_query($link, $query)) {
while ($row=mysqli_fetch_array($result)) {
$scheduletext="<tr><td>".$scheduletext.$row[1]."</td>";
$scheduletext="<td>".$scheduletext.$row[2]."</td>";
$scheduletext="<td>".$scheduletext.$row[3]."</td>";
$scheduletext="<td>".$scheduletext.$row[4]."</td></tr>";
}
}
$scheduletext=$scheduletext."</table>";
?>
<html>
<head>
<title>TastySnack - Production Schedule</title>
<link href="https://fonts.googleapis.com/css?family=Kaushan+Script" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="tasty.css">
</head>
<body>
<div id="top">
<div id="top-left">
TastySnack Production
</div>
<div id="top-right">
<img id="logo" src="images/TastysnackLogo.jpg">
</div>
</div>
<div id="split"></div>
<div id="schedule">
<?php
print_r($scheduletext);
?>
</div>
</body>
</html>
Click Here For Screenshot of Output
As #mister martin said in comment use dot to concatinate your string
$scheduletext ="<table>";
if($result = mysqli_query($link, $query)) {
while ($row=mysqli_fetch_array($result)) {
$scheduletext .="<tr><td>".$scheduletext.$row[1]."</td>";
$scheduletext .="<td>".$scheduletext.$row[2]."</td>";
$scheduletext .="<td>".$scheduletext.$row[3]."</td>";
$scheduletext .="<td>".$scheduletext.$row[4]."</td></tr>";
}
}
$scheduletext .="</table>";
If i choose a meal than come the price not in the textbox.
What i want is that if i choose an option in the selectbox that the texbox automatic fills with the price.
<!DOCTYPE html>
<?php
include ("connection.php");
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="test.css">
<meta charset="utf-8">
<title>Kantine</title>
</head>
<body>
<div id="container">
<div id="logo"></div>
<div id="header">
<h1> Change or Delete meals</h1>
</div>
<div id="menu"></div>
<div id="content">
<?php
echo '<select name="Meals">';
$result = mysqli_query($con,"SELECT meal, price FROM meals") ;
while($row = $result->fetch_assoc())
{
echo "<option value=\""."\">" . $row['meal']."</option>\n";
echo "<br />";
}
echo '</select>';
echo '<input type="text" value="' . $row['price'] . '"/>';
mysqli_close($con);
?>
</div>
<div id="footer"></div>
</div>
</body>
</html>
PHP is not suitable for client side scripting. What you want depend on the user choice on the browser side, therefore you'll need Javascript for that. If that action requires a database connection then you may want to use AJAX to connect to a PHP script and get the query results.
Take a look at the jQuery framework and specifically to the ajax section of it.
Have you tried escaping the " in your first echo? Also some of your html can be moved out of the php section, and you dont need linebreaks between option elements. And mixing single and double quotes is a sure way to get into trouble. Be consistent.
<select name="Meals">
<?php
$result = mysqli_query($con,"SELECT meal, price FROM meals") ;
while($row = $result->fetch_assoc())
{
echo "<option value=\"". $row['meal'] . "\">" . $row['meal'] . "</option>";
}
echo "<input type=\"text\" value=\"" . $row['price'] . "\"/>";
mysqli_close($con);
?>
</select>
I have a list of names in a database that i want to display one by one
(also for bonus points, another column in the database is a Boolean value for if a task is completed or not. if this is true i want the css content box background to be green instead of red.)
so how can i select a name from row one, put it to a PHP variable, then select the value from the "Name" column in row 2 and put that to another PHP variable or the next item in the array?
thanks for any help!
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="mngPWinCSS.css"/>
</head>
<body>
<?php
$dsn ='mysql:host=****.******.com;dbname=o****_**n';
$username='********';
$password ='******';
mysql_connect('localhost',$username,$password);
$query=mysql_query("SELECT Name FROM CLOAS_Team LIMIT 0,1");
$bob="dkajfk";
$url=$_SERVER['REQUEST_URI'];
header("Refresh: 60; URL=$url");
$com[1]="i";
$com[2]="i";
$com[3]="i";
$com[4]="i";
$com[5]="i";
$com[6]="i";
$name=mysql_fetch_array($query);
?>
<div id="content">
<img src="logjpg.JPG" alt="Smiley face" height="50" width="200">
<h3>CLOAS Tracker</h3>
</div>
<div id="Content">
<?php
?>
<div id="complete">
<h3names>
<?php
echo $name['Name'];
?>
</h3names>
</div>
<div id="incomplete">
<h3names>Name2</h3names>
</div>
</div>
</body>
</html>
First you need to change your SELECT query to select all of the rows that you wish to display, perhaps by taking off the LIMIT clause. Something like this;
$result=mysql_query("SELECT Name FROM CLOAS_Team");
(This will get you all of the names in your table.)
Next, you need to loop through the results you got from this query, like so;
$names = array();
while($row = mysql_fetch_assoc($result))
{
$names[] = $row['Name'];
}
This will put them into the array $names for you, which you can then work with. Instead of putting them into the array, you might want to output them immediately, perhaps like this;
while($row = mysql_fetch_assoc($result))
{ ?>
<div>
<h3>
<?php
echo $row['Name'];
?>
</h3>
</div>
<?php } ?>
However, you have many more errors in your code. Such as;
You can't just invent html elements called <h3names>
I doubt that you want to set the id attribute to 'incomplete'. An id should be unique, I expect you should be putting this in as a class (class = "incomplete")
I don't think your line header("Refresh: 60; URL=$url"); will do anything as your headers have already been sent to the page. If you want this line to work, it needs to be right at the top, BEFORE any output has been sent to the browser.
And for the bonus point, include the 'Completed' field in your query (if that is what it is called) and use this to add a style to each <div> element that you display in your loop. So your query might become;
$result=mysql_query("SELECT Name, Completed FROM CLOAS_Team");
And your loop would now be like this;
while($row = mysql_fetch_assoc($result))
{ ?>
<div style = "background-color:<?php echo $row['Completed'] == true ? 'green' : ' red'; ?>">
<h3>
<?php
echo $row['Name'];
?>
</h3>
</div>
<?php } ?>