Jump to content

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

What do you mean dynamically? You're being quite vague. If you want to display a different image each time you'll need to use PHP to choose the image and then echo it out...

...
<td><img src="<?=$imageURL;?>" /></td>
...
Edited by cpd

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.

Edited by cpd

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.

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.