Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,289 members, 7,807,980 topics. Date: Thursday, 25 April 2024 at 01:04 AM |
Nairaland Forum / Science/Technology / Programming / Php Gurus Help Urgently (665 Views)
Please Php Gurus, Help Me / Php Gurus Help Me Out: What Is Wrong With My Code?? / Php Gurus, Showcase Your Best Applications Here (2) (3) (4)
Php Gurus Help Urgently by Taiw(m): 5:38pm On Aug 13, 2013 |
I'm trying to display a column(field) in a table from mysql to populate a table(with 3columns,1row)i.e to spread across the 3 columns without repeating data.{highlighted in red} <?php $sql = "SELECT company FROM company "; $result = mysql_query($sql, $conn); //If no category, let the user know. if (mysql_num_rows($result) == 0) { echo " <br>\n"; echo " sorry, could not locate jobs by company. Please check back\n"; } else { while ($row = mysql_fetch_array($result)) { echo "<div class=\"pubdate\">"; echo "<table class=\"company_table\">"; echo "<tr>"; echo "<td><a href=\"#\">" . htmlspecialchars($row['company']) . "</a>;</td>"; echo "<td><a href=\"#\">" . htmlspecialchars($row['company']) . "</a>;</td>"; echo "<td><a href=\"#\">" . htmlspecialchars($row['company']) . "</a>;</td>"; echo "</tr>"; echo "</table>"; echo "</div>\n"; } } ?> thats d best i could do but apparently, the datas are repeated. Alternative suggestions will be welcomed.(its not compulsory i use tables but its neccessary i group it into 3) thanks |
Re: Php Gurus Help Urgently by nollyj: 6:19pm On Aug 13, 2013 |
If you need 3 columns and only 1 row, you are close to it. echo "<div class=\"pubdate\">"; echo "<table class=\"company_table\">"; // include this variable if the returned data is more than three int three_columns = 0; while ($row = mysql_fetch_array($result)) { three_columns++; echo "<td><a href=\"#\">" . htmlspecialchars($row['company']) . "</a>;</td>"; if(three_columns == 3)break; } echo "</tr>"; echo "</table>"; I did not test this code but you can get some idea. Let me know if you have more questions. echo "</div>\n"; |
Re: Php Gurus Help Urgently by Taiw(m): 8:21pm On Aug 13, 2013 |
after making some adjustments to your code, it worked // include this variable if the returned data is more than three $i= 0; while ($row = mysql_fetch_array($result)) { $i++; echo "<td><a href=\"#\">" . htmlspecialchars($row['company']) . "</a>;</td>"; if($i == 3)break; } echo "</tr>"; echo "</table>"; echo "</div>\n"; thanks man. You're a genius...I'm so grateful...i'll kip in touch if i get into any trap. |
Re: Php Gurus Help Urgently by nollyj: 10:37pm On Aug 13, 2013 |
You are welcome. I am glad I can be of help. Sorry for the typed variable (int three_columns). Sometimes I mistakenly port Java or another language to Php. |
(1) (Reply)
Citanda! Now On Mobile Phone Browser / Creating A Mobile-friendly Website In PHP / Python
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15 |