PHP+MySQL Printing a MySQL array into table -
i have query function (code below) use read db , know how loop print output -all- results table this:
i used it:
$visa=$db->query("select fname,lname,email users"); echo '<table bordercolor=black>'; ?> <tr> <th>name</th><th>lastname</th><th>e-mail</th> </tr> <?php echo "<td>"; echo $visa[0]['fname']; echo "</td>"; echo "<td>"; echo $visa[0]['lname']; echo "</td>"; echo "<td>"; echo $visa[0]['email']; echo "</td>";
the query function:
function query($querytext) { $rs = mysql_query($querytext, $this->_link); if($this->_debug) { $this->adddebugmessage("\t<tr>\n\t\t<td class=\"debug_nr\">".$this->_querycount++."</td>\n\t\t<td class=\"debug_queinfo\"><b>query: (".@mysql_num_rows($rs).")</b></td>\n\t\t<td>" . htmlspecialchars($querytext) . "</td>\n\t</tr>\n"); if(mysql_error() != '') { $this->adddebugmessage("\t<tr>\n\t\t<td class=\"debug_nr\">".$this->_querycount++."</td>\n\t\t<td class=\"debug_queinfo\"><b>error #".mysql_errno($this->_link)." :</b></td>\n\t\t<td>" . htmlspecialchars(mysql_error($this->_link)) . "</td>\n\t</tr>\n"); } } if($rs) { $num_rows = @mysql_num_rows($rs); if($num_rows) { if($num_rows > 0) { $rsarray = array(); while($line = mysql_fetch_array($rs , mysql_assoc)) { array_push($rsarray, $line); } mysql_free_result($rs); return $rsarray; } else { return false; } } else { if(mysql_affected_rows($this->_link) > 0) { return true; } else { return false; } } } else { return false; } }
use or foreach loop:
<?php foreach($visa $v) { echo "<td>"; echo $v['fname']; echo "</td>"; echo "<td>"; echo $v['lname']; echo "</td>"; echo "<td>"; echo $v['email']; echo "</td>"; }
in code, $visa
array of query results, , display values form have loop on array
Comments
Post a Comment