php explode text from mysql database into table -


i have text field in database new item, or subject separated using "-"

i have exploded text , made appear in table each item, or subject displayed in new row.

the problem have want able code no matter how many items in text field script echo number of rows - blank cells echoed..

for example there text field is: "- hello - - name - - something" fill top 5 rows, leaving others displaying blank.

thanks in advance!

echo "<table border=1 cellpadding=5 width=60% style='border-collapse:collapse; height:auto; font-size:small; float:left;'>                 <tr>                     <th style='background-color:#ffffcc';>this weeks objectives</th>                 </tr>";             // split data use of "-" seperate rows                       while ($row3 = mysql_fetch_assoc($objective)) {                 $str = $row3['objectives'];                 $splitstr = explode('-', $str);                 $int1 = intval($splitstr[0]);                 $int2 = intval($splitstr[1]);                 $int3 = intval($splitstr[2]);                 $int4 = intval($splitstr[3]);                 $int5 = intval($splitstr[4]);                 $int6 = intval($splitstr[5]);                 $int7 = intval($splitstr[6]); echo "<tr>";                      echo "<td style='background-color:#ffffff;text-align:left;'>" . $splitstr[1] . " " . $splitstr[2] . " </td>";                 echo "</tr>";                 echo "<tr>";                      echo "<td style='background-color:#ffffff;text-align:left;'>" . $splitstr[2] . "</td>";                 echo "</tr>";                 echo "<tr>";                      echo "<td style='background-color:#ffffff;text-align:left;'>" . $splitstr[3] . "</td>";                 echo "</tr>";                 echo "<tr>";                      echo "<td style='background-color:#ffffff;text-align:left;'>" . $splitstr[4] . "</td>";                 echo "</tr>";                 echo "<tr>";                      echo "<td style='background-color:#ffffff;text-align:left;'>" . $splitstr[5] . "</td>";                 echo "</tr>";                 echo "<tr>";                      echo "<td style='background-color:#ffffff;text-align:left;'>" . $splitstr[6] . "</td>";                 echo "</tr>"; echo "</table>"; 

use loop. instance:

$objectives = explode('-', $str);  foreach ($objectives $objective) {     echo "<tr><td style='background-color:#ffffff;text-align:left;'>" . $objective . "</td></tr>\n"; } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -