gojakie Posted December 18, 2008 Share Posted December 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/ Share on other sites More sharing options...
rhodesa Posted December 18, 2008 Share Posted December 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/#findComment-718961 Share on other sites More sharing options...
gojakie Posted December 18, 2008 Author Share Posted December 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/#findComment-719027 Share on other sites More sharing options...
rhodesa Posted December 18, 2008 Share Posted December 18, 2008 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/#findComment-719054 Share on other sites More sharing options...
gojakie Posted December 18, 2008 Author Share Posted December 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/#findComment-719081 Share on other sites More sharing options...
premiso Posted December 18, 2008 Share Posted December 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/#findComment-719085 Share on other sites More sharing options...
rhodesa Posted December 18, 2008 Share Posted December 18, 2008 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/#findComment-719087 Share on other sites More sharing options...
gojakie Posted December 18, 2008 Author Share Posted December 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/137560-solved-adding-hyperlink-for-one-of-the-element/#findComment-719116 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.