Parašė sNocK· 2014 Lap. 27 17:11:56
#1
Sveiki,
turiu susikures
MySQL'e bazeje table pavadinimu 'progs' ir ten yra 7 skiltys:
yra scriptas, kuris atspausdina lentele mano pasirinktajame admin.php puslapyje. Kaip matote, yra header'is "Baigtis", kuriame galiu parasyti WIN/LOSE/DRAW. Mano noras butu padaryti, kad jeigu as irasau WIN, tai ji atspausdina zalia spalva, LOSE - raudona, o DRAW - pilka. Kaip tai padaryti?
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';
$database = 'test';
$table = 'progs';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<table cellpadding='2' align='center' width='100%'><tr class='tr3'>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr class='tr4'>";
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
?>