Hi everyone, I am trying to make php swap a tumbnail image from a table.

so here is what I have:
<table>

<tr>
<td><img id="img1 name="img1" src="/img1.jpg" /></td>
</tr>
<tr>
<td><img id="img2 name="img2" src="img2.jpg" /></td>
</tr>
<tr>
<td><img id="img3 name="img3" img3.jpg" /></td>
</tr>
</table>
so I need PHp to be able to use the name attribute to echo one of the images and swap the images on refresh. ( or how can i even just echo one of the images) the swapping image would be a tumbnail so the size need to be reduced as well. ( i can do that from the html.)

Thanks

    First of all, the name attribute is deprecated in favour of id. Since you already have the id attribute you might as well just drop the name.

    Secondly: PHP doesn't know anything about your HTML - it's just a big lump of text that it sent out to the browser at some time in the past and then forgot about - so it doesn't know anything about any tag's attributes.

    But assuming that in your PHP script you have a variable $image in which you have the name/id of the image you want displayed:

    echo '<td>';
    switch($image)
    {
        case 'img1': $id = 'img1'; $src = '/img1.jpg'; break;
        case 'img2': $id = 'img2'; $src = '/img2.jpg'; break;
        // ....
    }
    echo "<img id='$id' src='$src' />";
    echo '</td>';
    

    For the examples given there's some redundancy that suggests further simplifications may be possible.

      Hi Weedpacket and thanks for your response. what I was actually hoping to accomplish was to be able to have php actually load any image within the table. so lets say that I add an id on my table called "img" I would like php to resize every image inside the table "img " so I can echo it, also it should be able to swap the images withhin "img".

      Thanks for all your help.

        Write a Reply...