Jump to content

How to add image inside of a TD?


raysefo

Recommended Posts

Hello,

 

I have a table as follows;

echo "
<form method='get'>
<center><img border='0' src='contest_winner.jpg' alt='test' width='452' height='384' class='center'></center>
<table class='imagetable center'>
<tr>
	<th>5/36</th>
	<th>6/40</th>
</tr>
<tr>
	<td>
		<select name='game1'>
			<option value='1'>111111</option>
			<option value='2'>222222</option>
		</select>
	</td>
	<td>
		<select name='game2'>
			<option value='1'>111111</option>
			<option value='2'>222222</option>
		</select>
	</td>
</tr>
<tr>
	<td>
		<input name='send1' type='submit' value='Check'>
	</td>
	<td>
		<input name='send2' type='submit' value='Check'>
	</td>
</tr>
<tr>
	<td>
		<-------- image here ----------->
	</td>
	<td>
		<-------- image here ----------->
	</td>
</tr>
</table>


</form>";

I would like to add an image between TD's at the last TR of the table. How can I do it dynamically?

 

Best Regards.

Link to comment
https://forums.phpfreaks.com/topic/278828-how-to-add-image-inside-of-a-td/
Share on other sites

Hi,

 

Here is my sample code, but I am getting Parse error: syntax error, unexpected '?' in C:\wamp\www\test.php on line 72

<?php
function form(){
echo "
<form method='get'>
<center><img border='0' src='contest_winner.jpg' alt='test' width='452' height='384' class='center'></center>
<table class='imagetable center'>
<tr>
	<th>5/36</th>
	<th>6/40</th>
</tr>
<tr>
	<td>
		<select name='game1'>
			<option value='1'>111111</option>
			<option value='2'>222222</option>
		</select>
	</td>
	<td>
		<select name='game2'>
			<option value='1'>111111</option>
			<option value='2'>222222</option>
		</select>
	</td>
</tr>
<tr>
	<td>
		<input name='send1' type='submit' value='Check'>
	</td>
	<td>
		<input name='send2' type='submit' value='Check'>
	</td>
</tr>
<tr>
	<td>
		<img border='0' src="<?=$imageURL;?>" width='24' height='24' >
	</td>
	<td>
		<img border='0' src="<?=$imageURL;?>" width='24' height='24' >
	</td>
</tr>
</table>


</form>";

Now it is OK but no images, probably path problem?

<?php
function form($imageURL){
echo "
<form method='get'>
<center><img border='0' src='contest_winner.jpg' alt='test' width='452' height='384' class='center'></center>
<table class='imagetable center'>
<tr>
	<th>5/36</th>
	<th>6/40</th>
</tr>
<tr>
	<td>
		<select name='game1'>
			<option value='1'>111111</option>
			<option value='2'>222222</option>
		</select>
	</td>
	<td>
		<select name='game2'>
			<option value='1'>111111</option>
			<option value='2'>222222</option>
		</select>
	</td>
</tr>
<tr>
	<td>
		<input name='send1' type='submit' value='Check'>
	</td>
	<td>
		<input name='send2' type='submit' value='Check'>
	</td>
</tr>
<tr>
	<td>
		<img border='0' src='<?=$imageURL;?>' width='24' height='24' >
	</td>
	<td>
		<img border='0' src='<?=$imageURL;?>' width='24' height='24' >
	</td>
</tr>
</table>


</form>";

}



 $imageURL = "Circle-apply-icon.png";
 form($imageURL);

Why have you wrapped a very specific form in a function called "form"? Just write the HTML as you would normally, above that open PHP tags and set the image URL.

 

E.g.

<?php
 
// Do some stuff
 
// Set the image
$imageURL = ...
 
?>
<html>
    <head>
 
    </head>
    <body>
        <form>
            <img ... />
        </form>
    </body>
</html>

I assume you're not going to actually set the image URL like that? And yes its probably a path issue. Assuming you've uploaded the image properly, use the URL you would to view the image in a browser.

I don't see how a semicolon change would fix it ...

 

 

<?php
function form($imageURL){
echo "
<form method='get'>
<center><img border='0' src='contest_winner.jpg' alt='test' width='452' height='384' class='center'></center>
<table class='imagetable center'>
<tr>
	<th>5/36</th>
	<th>6/40</th>
</tr>
...
<tr>
	<td>
		<img border='0' src='<?=$imageURL;?>' width='24' height='24' >
	</td>
	<td>
		<img border='0' src='<?=$imageURL;?>' width='24' height='24' >
	</td>
</tr>
</table>


</form>";

}

 

Lines 14 & 17: You are ALREADY in PHP, you can't jump back into PHP, remove the <?= and ;?> characters and you should be OK since you are just trying to imbed a variable into a string you are echoing.

Archived

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

×
×
  • 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.