Jump to content

[SOLVED] adding hyperlink for one of the <td> element


Recommended Posts

    echo "<table>";
    $handle = fopen($url, "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
    {
        echo "<tr>";
        foreach($data as $d)
            echo "<td>$d</td>";
            echo "<td>View</td>";
        echo "</tr>";
    }
    fclose($handle);
    echo "</table>";

 

The output of the above code is a table which is a grid of 100 rows and 12 columns. The last column is the <td>View</td> on which I need to add a hyperlink after clicking on which it should open a small window-like page without toolbars/menubars that should contain an image. The name of the image will be text in the first column.jpg

 

Example

 

A B C D E F G H I J K View

L M N O P Q R S T U V View

 

If I click on the first View, I should get a page with an image embeded in it A.jpg

 

If I click on the first View, I should get a page with an image embeded in it B.jpg

 

Thanks

    echo "<table>";
    $handle = fopen($url, "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
    {
        echo "<tr>";
        foreach($data as $d)
            echo "<td>$d</td>";
        echo "<td onclick=\"window.open('{$data[0]}.jpg','','status=0,toolbar=0,location=0,menubar=0,directories=0,width=350,height=250');\">View</td>";
        echo "</tr>";
    }
    fclose($handle);
    echo "</table>";

 

for more on window.open look here: http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

It works. Thanks

 

But the word "View" doesn't look like hyperlink. It looks like a normal font. Even if I put my mouse over it, it the cursor doesn't change to finger, it looks like a arrow. The user will not understand that this is a link. I had put a <u> element to underline it, but it doesn't look like a link. It works though

 

I want to add one more column to my table at the end next to "View". The content of this column would be a small image 15x15 pixel image. There are three images. If the third column has a negative number, the last column should show n.jpg. p.jpg for positive number and z.jpg for zero.

 

Thanks

    echo "<table>";
    $handle = fopen($url, "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
    {
        echo "<tr>";
        foreach($data as $d)
            echo "<td>$d</td>";
        echo "<td><a href="{$data[0]}.jpg" onclick=\"window.open('{$data[0]}.jpg','','status=0,toolbar=0,location=0,menubar=0,directories=0,width=350,height=250');return false;\">View</a></td>";
        echo "</tr>";
    }
    fclose($handle);
    echo "</table>";

It gives me an error arse error: syntax error, unexpected '{', expecting ',' or ';'

 

I tried this thrice. I then changed the string to the previous one that you gave which worked and again tried the second solution but the same error.

 

I am also looking solution for the second question where I want to add one more column to my table at the end next to "View". The content of this column would be a small image 15x15 pixel image. There are three images. If the third column has a negative number, the last column should show n.jpg. p.jpg for positive number and z.jpg for zero.

 

Thanks

    echo "<table>";
    $handle = fopen($url, "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
    {
        echo "<tr>";
        foreach($data as $d)
            echo "<td>$d</td>";
        echo "<td><a href=\"{$data[0]}.jpg\" onclick=\"window.open('{$data[0]}.jpg','','status=0,toolbar=0,location=0,menubar=0,directories=0,width=350,height=250'); return false;\">View</a></td>";
        echo "</tr>";
    }
    fclose($handle);
    echo "</table>";

 

Needed to escape the quotes around the href= portion.

yeah...forgot to escape the quotes:

    echo "<table>";
    $handle = fopen($url, "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
    {
        echo "<tr>";
        foreach($data as $d)
            echo "<td>$d</td>";
        echo "<td><a href=\"{$data[0]}.jpg\" onclick=\"window.open('{$data[0]}.jpg','','status=0,toolbar=0,location=0,menubar=0,directories=0,width=350,height=250');return false;\">View</a></td>";
        if($data[2] < 0)
            echo "<td><img src=\"n.jpg\" alt=\"Negative\"/></td>";
        elseif($data[2] > 0)
            echo "<td><img src=\"p.jpg\" alt=\"Positive\"/></td>";
        else
            echo "<td><img src=\"z.jpg\" alt=\"Zero\"/></td>";
        echo "</tr>";
    }
    fclose($handle);
    echo "</table>";

yeah regarding escaping quotes, even I thought so as the error was self explanatory. Since I am beginner to php and no knowledge of programming and syntax, I was not able to figure out which quote to change/remove.

 

Issue is resolved. Thank you very much.

 

One request. One of my post is still unanswered. The subject is Beginner in PHP - Need modification in a code and topic id is 230455. Mchl was helping me on that but no responses later. Can you guys help? I have posted 4 problems at the last post and looking answers for that.

 

Thanks again.

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.