What is wrong with my PHP code?
-
I need my PHP code to print out a table filled in with this information: RonPaul|4|http://www.ronpaul.com%7CRon Paul BarackObama|5|http://www.barackobama.com/splash/obama-clooney-you-get-started?%7CBarry NewtGingrich|4|http://www.newt.org/%7CNewt MittRomney|3|http://www.mittromney.com/s/mitt-ann-2012%7CRomney MittRomney|2|http://en.wikipedia.org/wiki/Mitt_Romney%7CWiki article about Romney RickSantorum|4|http://en.wikipedia.org/wiki/Santorum%7CWiki article about Santorum RonPaul|2|http://en.wikipedia.org/wiki/Ron_paul%7CWiki article about Paul RonPaul|1|http://www.ronpaulforums.com/%7CForums about Ron Paul This information translates into $cat|$rating|$url|$desc cat = category desc = description The table is separated into three columns: Rating, URL, and Description. This table takes the information I mentioned above and sorts it into a categories based on the names of the politicians. It then sorts lists the rating, website url, and description in the appropriate columns. I have a huge problem. The url is supposed to generate as a link, but everything generates as a link. Also, some columns span longer than others. If there are more than one website in a category, only the first website is generated as a link and all the following rows have no links at all. I had help with this code and I don't understand the logic of it very well at all. Someone told me something about break logic, but I didn't understand their explanation very well. Please, any insight will be super helpful! Here is the code: <?php $file = file('../write/myfile.txt'); sort($file); $main = array(); foreach($file as $key =>$value) { $main[$key]=explode("|",$value); } //columns $columns = array('Rating', 'URL', 'Description'); $counter=0; $category=''; $newCat = true; foreach($main as $key => $value){ if($counter==0) { echo "<table border=1 align=center><tr>"; foreach($columns as $col) { echo "<th> $col </th>"; } echo "</tr>"; $counter++; } if($category !== $main[$key][0]) { $category = $main[$key][0]; $newCat = true; echo "<tr><td colspan='4' > <b>$category</b></td>"; } else { $newCat = false; } echo "<tr>"; for($i=1; $i< count($main[$key]); $i++) { $v = $main[$key][$i]; if($i==2 && !$newCat) { echo "<td colspan='2'> $v </td>"; } else { echo "<td> <a href=$v>$v</> </td>"; } } echo "</tr>"; } echo "</table>"; ?> The information is located in the myfile.txt, but since you can't see it I pasted it above. Any help is greatly appreciated.
-
Answer:
You are not closing the links properly. This line: echo "<td> <a href=$v>$v</> </td>"; should be echo "<td> <a href=\"$v\">$v</a> </td>"; (note that I have added quotes around the URL and escaped them, and corrected </> to </a>)
Matt at Yahoo! Answers Visit the source
Related Q & A:
- How can I debug my php code?Best solution by Stack Overflow
- What's wrong with this PHP Twitter API POST?Best solution by Stack Overflow
- What is wrong with this Laravel 5 response?Best solution by Stack Overflow
- What's wrong with my yahoo 360 page stat counter?Best solution by answers.yahoo.com
- What is wrong with my only tv?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.