Show checkbox with database value - php

I am having trouble with a part of my code. I want the checkbox in the last column to be checked if the corresponding DB value is 1, but something keeps going wrong with my code, anyone who sees what's wrong? It's probably very simple but I can't find it.
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
$betaald = $record['betaald'];
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald' id='betaald' value='1' ". echo ($betaald==1 ? 'checked' : ''); . " ></td>";
echo "</tr>";
}
mysql_close($con);
?>

<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData = mysql_query($sql, $con);
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php while ($record = mysql_fetch_array($myData)) { ?>
<tr>
<td><?php echo $record['naam'] ?></td>
<td>
<input type='checkbox' name='betaald' id='betaald' value='1'
<?php if($record['betaald'] == 1){ ?>
checked="checked"
<?php } ?>
/>
</td>
</tr>
<?php } ?>
</table>

Try this
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData= mysql_query($sql) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald</b></th>
</tr>
<?php
while($record = mysql_fetch_array($myData))
{
?>
<tr>
<td> <?php echo $record['naam'] ?></td>
<td> <input type='checkbox' name='betaald' id='betaald' value='1' <?php echo ($record['betaald']==1 ? 'checked' : '')?>> </td>
</tr>
<?php
}
mysql_close($con);
?>
mysql_query($sql) no need to define $con
Note: This extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0

<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
while($record = mysql_fetch_array($myData)) {
$betaald = $record['betaald'];
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald' id='betaald' value='1' ";
echo $betaald==1 ? 'checked' : '';
echo " ></td>";
echo "</tr>";
}
mysql_close($con);
?>
You have assigned $betaald value outside the while loop so there is no value in $betaald.
I have included $betaald inside while loop.

You need several changes in your php and html code. First of all I've some confusion about your code. Let me clear those.
Point 1 [name='betaald']: If you have a name like this you will not get multiple selected value.
Point 2 [id='betaald']: ID must be unique in a page.
Point 3 [value='1']: How will you differ values if all have same value?
so your code should be something like this:
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
$betaald = $_POST['betaald'];
$i = 1;
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald[]' id='betaald".$i."' value='".$record['betaald']."' ";
if ($record['betaald'] == $betaald)
{
echo "checked";
}
echo " ></td>";
echo "</tr>";
$i++;
}
mysql_close($con);
?>

Related

How to show a button on selecting the value in DropDown List

As a beginner in PHP.
I have a dropdownlist of event names and a button, And I tried to display it only when I selecting any value > 0 only. Please help me out.
Thanks in advance
<?Php
#$event=$_GET['event'];
if(strlen($event) < 0 ){
echo "Data Error";
exit;
}
$sql="SELECT id,event_name FROM wp_evr_event order by id";
if(isset($event) and strlen($event) > 0){
$quer="SELECT id,fname,status,email,event_id FROM wp_evr_attendee where event_id=$event order by fname";}
else{$quer="SELECT id,fname,status,email,event_id FROM wp_evr_attendee order by event_id";}
echo "<form method=post name=Reload action=''>";
echo "<select name='event' onchange=\"reload(this.form)\"><option value=''>please select..</option>";
foreach ($con->query($sql) as $row){
if($row['id']==#$event){echo "<option selected value='$row[id]'>$row[event_name]</option>"."<BR>";}
else{echo "<option value='$row[id]'>$row[event_name]</option>";
}
}
echo "</select>";
?>
</div>
<div class="container">
<table>
<tr>
<td class='c_td'>id</td>
<td class='c_td'>name</td>
<td class='c_td'>status</td>
<td class='c_td'>email</td>
<td class='c_td'>event_id</td>
<td class='c_td'>edit</td> <td>delete</td>
</tr>
<?php
$i=1;
foreach ($con->query($quer) as $row2) {
$i=$i+1;
?>
<tr>
<td class='i_td'><?php echo $row2['id'] ?> </td>
<td class='i_td'><?php echo $row2['fname'] ?> </td>
<td class='i_td'><?php echo $row2['status'] ?> </td>
<td class='i_td'><?php echo $row2['email'] ?> </td>
<td class='i_td'><?php echo $row2['event_id'] ?> </td>
</tr>
<?php
}
?>
Because only the names of attendees will be exported for the selected event
<?php
echo '<td><a class="btn" href="test3.php?event=' . $row2['event_id'] . '">Export To Excel</a> </td>';
?>
I tried this
select:invalid + button {
display: none;
}

How to show the clicked table row id in the address bar

I have a PHP based website for jobs. I echo all the jobs from database in a table below. When i click on a job in table row it shows the job details in an iframe beside the table.
This is the code of the table and iframe index.php
<table class="table1">
<tr>
<td colspan="3">
<?php
include "job.header.php";
?>
</td>
</tr>
<tr>
<td width="30%">
<div>
<?php
require "module/job.call.php";
?>
</div>
</td>
<td width="60%">
<iframe name="content" src="../module/job.unclicked.php">
</iframe>
</td>
<td width="20%"> </td>
</tr>
</table>
This is the code that i call jobs from the database job.call.php
<?php
$result = mysqli_query($conn,"SELECT * FROM job where approved='1' ORDER BY `CreatedTime` DESC");
echo "<table id='maintable' class='table-fill' border='0' cellpadding='0' cellspacing='0'>
<tr>
<th position='fixed' overflow='hidden' width='10%'>Job Title</th>
<th position='fixed' width='5%'>Company Name</th>
<th width='5%'>Closing Date</th>
</tr>";
while($row = mysqli_fetch_array($result) ) {
if (strlen($row['positiontitle']) > 20)
$row['positiontitle'] = substr($row['positiontitle'], 0, 60) . "...";
echo "<tr ref='job.details.php?id=".$row['id']."' target='content' class='positiontitle-link'>";
echo "<td><font style='text-shadow: none;'>" . $row['positiontitle'] . "</font></a></td>";
echo "<td>" . $row['companyname'] . "</td>";
echo "<td>" . $row['closingdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
I want that when i click on the job in the table row then the address bar should take the id of the job. because if someone wants to share the job then they should just send that address for specific job.
Now it show like this
I want that it should look like this

onmouseover not showing div

I have a table in my DB which I call to show everything in that table on a page one of the items in the table is an image which when moused over needs to show a popup showing data from a separate table which corresponds to that item. I have a JQuery which calls the data depending on the row from the 1st table but when I try to actually put the two together I get the first table showing fine but now I get no pop up on mouseover.
This page is currently included in the index.php page which has the scripts to call the .js / .css files.
Here's the code for what I am trying to do:
<html>
<table border='0' cellpadding='0' cellspacing='0' class="center2">
<tr>
<td width='60'><img src="images/box_tl.png"></td>
<td style="background: url(images/box_tm.png)" align="center"><img src="images/news.png"></td>
<td width='25'><img src="images/box_tr.png"></td>
</tr>
<tr>
<td style="background: url(images/box_ml.png)"><h2>.</h2></td>
<td style="background: url(images/box_mm.png)">
<?php
include 'connect.php';
$query = mysql_query("SELECT * FROM tbl_img") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Id</th> <th>Health</th> <th>Body</th> <th>Effects</th> <th>Spawn</th></tr></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query )) {
$mob_id = $row['mob_id'];
$mob = $row['mob'];
$body = $row['body'];
$mob_name = $row['mob_name'];
$health = $row['health'];
$level = $row['level'];
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<img src='/testarea/include/mobs/$mob' />";
echo "</td><td>";
echo $mob_name;
echo "</td><td>";
echo $level;
echo "</td><td>";
echo $health;
echo "</td><td>";
echo
"
<a onmouseover='popup($('#hidden-table').html(), 400);' href='somewhere.html'><img src='/testarea/include/mobs/dead/$body' /></a>
";
echo "
<div id='hidden-table' style='display:none;'>
<table border='0' cellpadding='0' cellspacing='0' class='center3'>
<tr>
<td width='14'><img src='images/info_tl.png'></td>
<td style='background: url(images/info_tm.png)' align='center'></td>
<td width='14'><img src='images/info_tr.png'></td>
</tr>
<tr>
<td style='background: url(images/info_ml.png)'><h2>.</h2></td>
<td style='background: url(images/info_mm.png)'>
";
$query2 = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width='250' id='2' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Item Name</th> <th>Qty</th></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query2 )) {
$id = $row['id'];
$item_img = $row['item_img'];
$qty = $row['qty'];
$item_name = $row['item_name'];
// Print out the contents of each row into a table
echo "<tr><td width='50'>";
echo "<img src='/testarea/item/$item_img' />";
echo "</td><td width='150'>";
echo $item_name;
echo "</td><td width='50'>";
echo $qty;
echo "</td></tr>";
}
echo "</tbody></table>";
echo "
</td>
<td style='background: url(images/info_mr.png)'><h2>.</h2></td>
</tr>
<tr>
<td width='14'><img src='images/info_bl.png'></td>
<td style='background: url(images/info_bm.png)' align='center'><h2>.</h2></td>
<td width='14'><img src='images/info_br.png'></td>
</tr>
</table>
</div>"
;
echo "</td><td>";
echo "test";
echo "</td><td>";
echo "test";
echo "</td></tr>";
}
echo "</tbody></table>";
?>
</td>
<td style="background: url(images/box_mr.png)"><h2>.</h2></td>
</tr>
<tr>
<td width='60'><img src="images/box_bl.png"></td>
<td style="background: url(images/box_bm.png)" align="center"><h2>.</h2></td>
<td width='25'><img src="images/box_br.png"></td>
</tr>
</table>
</html>
you have two semi-colons on this line...could be the problem
$query = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());;

div not showing with onmouseover

everything works perfect bar the div 'hidden-table' not showing, if i remove the 'style:display:none' then it shows the table with correct data so i know its working and i have tried the taking the popup out of the echo and displaying it separately just to see if it shows which it does.
seems the problem occurs only when its in the echo and seems centred around the 'onmousover'
full page code:
<html>
<table border='0' cellpadding='0' cellspacing='0' class="center2">
<tr>
<td width='60'><img src="images/box_tl.png"></td>
<td style="background: url(images/box_tm.png)" align="center"><img src="images/news.png"></td>
<td width='25'><img src="images/box_tr.png"></td>
</tr>
<tr>
<td style="background: url(images/box_ml.png)"><h2>.</h2></td>
<td style="background: url(images/box_mm.png)">
<?php
include 'connect.php';
$query = mysql_query("SELECT * FROM tbl_img") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Id</th> <th>Health</th> <th>Body</th> <th>Effects</th> <th>Spawn</th></tr></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query )) {
$mob_id = $row['mob_id'];
$mob = $row['mob'];
$body = $row['body'];
$mob_name = $row['mob_name'];
$health = $row['health'];
$level = $row['level'];
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<img src='/testarea/include/mobs/$mob' />";
echo "</td><td>";
echo $mob_name;
echo "</td><td>";
echo $level;
echo "</td><td>";
echo $health;
echo "</td><td>";
echo
"
<a onmouseover='popup($('#hidden-table').html(), 400);' href=''><img src='/testarea/include/mobs/dead/$body' /></a>
";
echo "
<div id='hidden-table' style='display:none;'>
<table border='0' cellpadding='0' cellspacing='0' class='center3'>
<tr>
<td width='14'><img src='images/info_tl.png'></td>
<td style='background: url(images/info_tm.png)' align='center'></td>
<td width='14'><img src='images/info_tr.png'></td>
</tr>
<tr>
<td style='background: url(images/info_ml.png)'><h2>.</h2></td>
<td style='background: url(images/info_mm.png)'>
";
$query2 = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());
echo "<table border='0' cellpadding='1' cellspacing='1' width='250' id='2' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Item Name</th> <th>Qty</th></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query2 )) {
$id = $row['id'];
$item_img = $row['item_img'];
$qty = $row['qty'];
$item_name = $row['item_name'];
// Print out the contents of each row into a table
echo "<tr><td width='50'>";
echo "<img src='/testarea/item/$item_img' />";
echo "</td><td width='150'>";
echo $item_name;
echo "</td><td width='50'>";
echo $qty;
echo "</td></tr>";
}
echo "</tbody></table>";
echo "
</td>
<td style='background: url(images/info_mr.png)'><h2>.</h2></td>
</tr>
<tr>
<td width='14'><img src='images/info_bl.png'></td>
<td style='background: url(images/info_bm.png)' align='center'><h2>.</h2></td>
<td width='14'><img src='images/info_br.png'></td>
</tr>
</table>
</div>"
;
echo "</td><td>";
echo "test";
echo "</td><td>";
echo "test";
echo "</td></tr>";
}
echo "</tbody></table>";
?>
</td>
<td style="background: url(images/box_mr.png)"><h2>.</h2></td>
</tr>
<tr>
<td width='60'><img src="images/box_bl.png"></td>
<td style="background: url(images/box_bm.png)" align="center"><h2>.</h2></td>
<td width='25'><img src="images/box_br.png"></td>
</tr>
</table>
</html>
You're inadvertently ending your onmouseover event when you try to reference your jQuery selector. The use of single quotes for different reasons is the reason. Try this instead:
function ShowPop()
{
popup($('#hidden-table').html(), 400);
}
<a onmouseover='ShowPop()' href=''><img ..... /></a>

Display specific image depending on specific text in MySQL table using PHP

In my MySQL database I have table named game with columns: sport_cat, timelive, match_title, selection,
I am exactly this MySQL query SELECT statement for displaying them in grid view on site:
<?
$qry = "
SELECT sport_cat,match_title,selection,
CASE
WHEN game.result LIKE '' THEN 'PENDING'
WHEN game.result LIKE game.selection THEN 'WON'
WHEN game.result NOT LIKE game.selection THEN 'LOST'
END AS result
FROM game
";
$searchText = "";
if($_REQUEST['search_text']!=""){
$searchText = mysql_real_escape_string($_REQUEST['search_text']);
$qry .=" WHERE sport_cat.timelive LIKE '%$searchText%' " .
" OR game.timelive LIKE '%$searchText%' " .
" OR game.match_title LIKE '%$searchText%' ";
}
$qry .= " ORDER BY timelive DESC";
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
?>
In first column sport_cat there are few possible text inputs: football, tennis, basketball.
HTML of my file where this part is looks like this:
<table>
<?if(mysql_num_rows($result)!=0){
$counter = $starting + 1;
while($data = mysql_fetch_array($result)) {?>
<tr>
<td align="center"><? echo $data['sport_cat']; ?></td>
<td align="center"><? echo $data['timelive']; ?></td>
<td align="center"><? echo $data['match_title']; ?></td>
<td align="center"><? echo $data['selection']; ?></td>
</tr>
<?
$counter ++;
} ?>
</table>
What I am trying to do is to display specific picture in those cell according to that input in cell. So if there is football want to display football.png picture or if there is tennis want to display tennis.png or if there is basketball want to display basketball.png.
Also, if there is maybe some unknown input like cricket and don't have picture specified for that word would like to display unknown.png picture.
Pictures are stored under images/icons on my server.
Now i'm not sure how to implement this code regarding picturing issue into this already existent i have.
Thanks.
ADDED full example code: 03.11.2011.:
<?php
error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');
mysql_connect('xxx.xxx.xxx.xx', 'xxxxxx', 'xxxxxxxx') or die(mysql_error());
mysql_select_db('xxxxxxx');
?>
<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<?
$qry = "
SELECT sport_cat,bidprice,timelive,match_title,selection,winnings_with_startamount,odds,odds*10 AS gainedodds,username,
CASE
WHEN game.result LIKE '' THEN 'pending'
WHEN game.result LIKE game.selection THEN 'WON'
WHEN game.result NOT LIKE game.selection THEN 'LOST'
END AS result
FROM game
";
$searchText = "";
if($_REQUEST['search_text']!=""){
$searchText = mysql_real_escape_string($_REQUEST['search_text']);
$qry .=" WHERE game.sport_cat LIKE '%$searchText%' " .
" OR game.timelive LIKE '%$searchText%' " .
" OR game.match_title LIKE '%$searchText%' " .
" OR game.selection LIKE '%$searchText%' " .
" OR game.username LIKE '%$searchText%'";
}
$qry .= " ORDER BY timelive DESC";
//for pagination
$starting=0;
$recpage = 10;//number of records per page
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
function getStyleColorForStatus($status) {
if ($status == 'WON') {
return '#99ff99';
}
else if ($status == 'LOST') {
return '#ff9999';
}
else if ($status == 'pending') {
return '#e5e5e5';
}
return '';
}
?>
<form name="form1" action="testpage.php" method="POST" style="background-color:#f9f9f9; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1);">
<table border="0" align="center" width="1000px" padding-left="0px" style="background:#F9F9F9;">
<TD colspan="0" style="padding-left:0px; padding-bottom:5px; padding-top:10px; text-align:center;">
Search: <input type="text" name="search_text" value="<?php echo $searchText; ?>">
<input type="submit" value="Search">
</TD>
<tr><TD colspan="0">
<div id="page_contents">
<table width="968px" cellspacing="0" cellpadding="5" align="center" frame="box" rules="none" style="padding-bottom:20px; margin-bottom:8px;margin-top:3px; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1); border: 1px solid #cccccc;">
<tr style="height: 50px;">
<td width="10%" align="center" td class="winheader"><div class="glowtext">Event Category</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Bid Cost</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Event Start Time</div></td></td>
<td width="35%" align="center" td class="winheader"><div class="glowtext">Market/Event</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Selection</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winnings</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Odds</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Gained Odds</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winning Bidder</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Final Result</div></td></td>
</tr>
<?
if(mysql_num_rows($result)!=0){
$counter = $starting + 1;
$pathImg = "/images/icons/";
while($data = mysql_fetch_array($result)) {
//calculate url image
$pathFile = $pathImg . $data['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
?>
<tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
<td align="center"><img src="<?=$pathFile?>" alt="<?=$data['sport_cat']?>"></TD>
<td align="center"><? echo $data['bidprice']; ?></TD>
<td align="center"><? echo $data['timelive']; ?></TD>
<td align="left"><? echo $data['match_title']; ?></TD>
<td align="left"><? echo $data['selection']; ?></TD>
<td align="center"><font color="green">€ <? echo $data['winnings_with_startamount']; ?></TD>
<td align="center"><? echo $data['odds']; ?></TD>
<td align="center"><? echo $data['gainedodds']; ?></TD>
<td align="center"><? echo $data['username']; ?></TD>
<td align="center" style="background-color:<?php echo getStyleColorForStatus($data['result']); ?>"><? echo $data['result']; ?></td>
</tr>
<?
$counter ++;
}
}
?>
<tr><TD align="center" colspan="10" style="padding-bottom:1px; padding-top:10px; color:#333;"><? echo $obj->anchors; ?></TD></tr>
<tr><TD align="center" colspan="10" style="padding-bottom:10px; padding-top:5px; color:#333;"><? echo $obj->total; ?></TD></tr>
<?}else{?>
<tr><TD align="center" colspan="10" style="padding-bottom:10px padding-top:10px; color:red;">No Data Found</TD></tr>
<?}?>
</TD></tr>
</table>
</div>
</tr>
</TD>
</form>
</table>
try this:
$sql = "SELECT * FROM game";
$result = mysql_query($sql) or die(mysql_error());
$pathImg = "/images/icons/";
while ($row = mysql_fetch_array($result)) {
$pathFile = $pathImg . $row['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
echo '<img src="' . $pathFile . '">';
}
You edit Ask and I edit Anwer :P
<table>
<?
if (mysql_num_rows($result) != 0) {
$counter = $starting + 1;
$pathImg = "/images/icons/";
while ($data = mysql_fetch_array($result)) {
//calculate url image
$pathFile = $pathImg . $data['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
?>
<tr>
<td align="center"><img src="<?=$pathFile?>" alt="<?=$data['sport_cat']?>"></td>
<td align="center"><? echo $data['sport_cat']; ?></td>
<td align="center"><? echo $data['timelive']; ?></td>
<td align="center"><? echo $data['match_title']; ?></td>
<td align="center"><? echo $data['selection']; ?></td>
</tr>
<?
$counter++;
}
}
?>
</table>
Something like the following should work.
<?php
$sql = "SELECT * FROM game";
$result = mysql_query($sql)or die(mysql_error());
while ($row = mysql_fetch_array($result)){
// Show images
if($row['sport_cat']=='football'){
print "<img src='football.png'/>";
}
elseif($row['sport_cat']=='basketball'){
print "<img src='basketball.png'/>";
}
elseif($row['sport_cat']=='tennis'){
print "<img src='tennis.png'/>";
}else{
print "<img src='unknown.png' />";
}
} // End while loop
?>

Categories