I made listview in jQuery Mobile and I used PHP to feed its contents. It works properly, but the code is too long and most part of it are very similar to each other. Is there any way to simplify the code? Please have a look at the code, then I'll explain what I really need to do:
<ol data-role="listview">
<?php
while ($row = mysql_fetch_array($result)){
echo "<li><a href=\"#\">";
// first column check
switch ($row[1]) {
case "Behnam":
echo " B . ";
break;
case "Tarin":
echo " T . ";
break;
}
// second column check
switch ($row[2]) {
case "Behnam":
echo " B . ";
break;
case "Tarin":
echo " T . ";
break;
default:
echo " N . ";
}
// third column check
switch ($row[3]) {
case "Behnam":
echo " B . ";
break;
case "Tarin":
echo " T . ";
break;
default:
echo " N . ";
}
// fourth column check
switch ($row[4]) {
case "Behnam":
echo " B . ";
break;
case "Tarin":
echo " T . ";
break;
default:
echo " N . ";
}
// fifth column check
switch ($row[5]) {
case "Behnam":
echo " B . ";
break;
case "Tarin":
echo " T . ";
break;
default:
echo " N . ";
}
// sixth column check
switch ($row[6]) {
case "Behnam":
echo " B ";
break;
case "Tarin":
echo " T ";
break;
default:
echo " N ";
}
echo "</li></a>";
}
?>
</a></li>
</ol>
and the result is:
By using while ($row = mysql_fetch_array($result)){
I can fetch each row of the sql table one by one. But I also need to check the value of each cell(column) as well.