Jump to content


This topic is now archived and is closed to further replies.


Putting an IF statement in table

Recommended Posts

Is it possible to add an IF statement in a table? My situation is, i want an image (Thumbnail) to appear depending on what filetype the file is. so i have radio buttons which return a value. I want to do an if statement so if for example 1 appears in the field, a word file icon will appear in the table.

Here is the coding for the form

echo "<tr>";
echo "<td><font face=Verdana size=-1>
<input type=radio value=1 name=filetype>&nbsp .doc<br>
<input type=radio value=2 name=filetype>&nbsp .pdf<br>
<input type=radio value=3 name=filetype>&nbsp .jpg<br>
<input type=radio value=4 name=filetype>&nbsp .bmp</td>";
echo "</tr>"


Here is the coding for the table


while ($row=mysql_fetch_row($result)){
echo "<td>".$row[3]."</td>";
echo "<td>  (This is where i do not understand how to place the IF statement) </td> ";
echo "<tr>";


Do i just create a if statment elsewhere, save the answer in a variable and then place the variable in the cell.

such as


if ($filetype == 1){
echo "<img src=word.gif alt=word icon>";
} else {
echo "<img src=adobeReader.gif alt=pdf icon>";


But then how do i save this into a variable.

I have no idea how to work around this

Help  ???


Share this post

Link to post
Share on other sites


//Get the file types.


//Get the filetypes out

foreach($x as $filetype){

// put the file types with in a radio button.

echo "<tr>
<td><font face=Verdana size=-1>

<input type=radio value=1 name=$filetype>&nbsp $filetype<br>


// Pull the radio button file types out.

foreach($filetype as $file){

// query the database for the filetype

$query="select * from files where filetype='$file'";


// show the file types from the database.

echo"<img src=" ".$record['filetype']." "></img>";




Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.