I have a table like this:
$sql = "CREATE TABLE dramaStudio
(
rowId varchar(1) not null,
columnId int not null,
status int,
firstName varchar(15) not null,
lastName varchar(15) not null,
updatedby varchar(10),
PRIMARY KEY (rowId, columnId)
)";
On the homepage of my website I would like the user to be able to see if there are any free seats without going on to the seating plan. Pretty much just a bit saying 'free seats:'followed by a number. My logic in pseudo code would be:
$j=0
select * from dramaStudio
for every status == 0
$j+1
echo $j
Any help will be greatly appreciated.
Assuming that status=0 if the free seat:
SELECT COUNT(*) AS freeseats FROM dramaStudio WHERE status=0
Full example, from php manual:
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
$query = "SELECT COUNT(*) AS freeseats FROM dramaStudio WHERE status=0";
$result = mysqli_query($link, $query);
/* associative array */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
echo $row['freeseats']; // this is an integer
/* free result set */
mysqli_free_result($result);
/* close connection */
mysqli_close($link);
?>
just do a COUNT on all the fields who have a status of 0?
SELECT COUNT(*) FROM dramaStudio WHERE status = '0'
See sample code
$con = mysql_connect("localhost", "peter", "abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person";
$result = mysql_query($sql,$con);
while ($property = mysql_fetch_field($result))
{
echo "Field name: " . $property->name . "<br />";
echo "Table name: " . $property->table . "<br />";
echo "Default value: " . $property->def . "<br />";
echo "Max length: " . $property->max_length . "<br />";
echo "Not NULL: " . $property->not_null . "<br />";
echo "Primary Key: " . $property->primary_key . "<br />";
echo "Unique Key: " . $property->unique_key . "<br />";
echo "Mutliple Key: " . $property->multiple_key . "<br />";
echo "Numeric Field: " . $property->numeric . "<br />";
echo "BLOB: " . $property->blob . "<br />";
echo "Field Type: " . $property->type . "<br />";
echo "Unsigned: " . $property->unsigned . "<br />";
echo "Zero-filled: " . $property->zerofill . "<br /><br />";
}
mysql_close($con);
you are storing the filled seat? to find out empty you have to specify number of colomn and rows.
and if the filled and empty seat is distinguishable on status in table. you can do like this,
$query = "select * from dramaStudio where status = 0";
$result_Set = mysql_query($query);
while($row = mysql_fetch_object($result_set)){
echo $row->rowId .',', $row->columnId;
echo '</br>';
}