Jump to content


Photo

Putting an IF statement in table


  • Please log in to reply
1 reply to this topic

#1 j3rmain3

j3rmain3
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 26 October 2006 - 10:55 AM

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

Thanks
J3rmain3

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 October 2006 - 11:16 AM


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

}
 }
   }

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users