WeCodeThings Library
Library of code bits
Glossary    Contact Us
Need a web designer? visit WeCodeThings.Com for more details
Search  
   
Browse by Category

WeCodeThings Library .: PHP .: PHP loop through sql statement and put data into a table using a while loop



PHP loop through sql statement and put data into a table using a while loop

Still being new to php, I was trying to make a SQL Query that would put information into a table.

Using PHP, here is how you complete a simple call to the SQL database and get in return a query, which you put into a table.

Heres what I came up with.

 

  1. <table border=1>
  2. <?php
  3.  
  4. mysql_connect("localhost", "username", "password") or die(mysql_error());
  5. mysql_select_db("controlcsi") or die(mysql_error());
  6.  
  7.  
  8. $summat = mysql_query("SELECT cllaccid, cllcustomid, cllstatus, cllname
  9.                      FROM tblcall_accid
  10.                       WHERE cllstatus= 'active'
  11.                       GROUP BY cllaccid, cllcustomid, cllstatus, cllname
  12.                     ");
  13.                                        
  14.                                                                                
  15. while ($row = mysql_fetch_assoc($summat)) {
  16.         $myid = $row['cllaccid'];
  17.                 echo '<tr><td>'.$myid.'</td>';
  18.         echo '<td>'.$row['cllcustomid'].'</td>';
  19.         echo '<td>'.$row['cllstatus'].'</td>';
  20.         echo '<td>'.$row['cllname'].'</td>';
  21.                 echo '<td><a href="group.php?myid='.$myid.'">Select</a></td></tr>';
  22.         }
  23. ?>
  24. </table>


How helpful was this article to you?

Related Articles

article ColdFusion Insert Data Statement Into a Table using ColdFusion CFC CFQueryParam
Be sure that when you type out the field...

  4-28-2009    Views: 1743   
article Flex 3 Get Data from a CFC ColdFusion using bindable result handler function
More about creating a remote object and...

(No rating)  4-21-2009    Views: 894   
article PHP ColdFusion Isset Isdefined Submit Form Know when a Form has Submitted using IF
When processing a form, you need to know...

(No rating)  5-8-2009    Views: 1922   

User Comments

Add Comment
No comments have been posted.




.: Powered by Lore .:Code by WeCodeThings Website Design and Development