Jump to content

Putting an IF statement in table


j3rmain3

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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.