Jump to content

Archived

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

j3rmain3

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
[code]

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>"

[/code]

Here is the coding for the table

[code]

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>";

[/code]

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

such as

[code]

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

[/code]

But then how do i save this into a variable.

I have no idea how to work around this

Help  ???

Thanks
J3rmain3

Share this post


Link to post
Share on other sites
[code]

<?php

//Get the file types.

$x=array('doc','pdf','jpg','bmp');


//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>

</tr>";


// Pull the radio button file types out.

foreach($filetype as $file){


// query the database for the filetype

$query="select * from files where filetype='$file'";
$result="mysql_query($query);

while($row=mysql_fetch_assoc($result)){


// show the file types from the database.

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

}
}
   }

?>

[/code]

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.