Get all the information from a list of data using foreach

Source: Internet
Author: User

List the Code First: (In admin/listadmin.php)

                      <?php foreach ($rows as $row):?>  //Note that the following foreach ($rows as $row) is followed by a colon that is not a comma                            <tr>                                <!-- Here the ID and for inside of the C1 need to loop out--                                <td><input type= "checkbox" id= "C1" class= "check" ><label for= "C1" class= "label" ><?php echo $row [' id '];? ></label></td>                                <td>x</td>                                <td>x</td>                                <td align= "center" ><input type= "button" value= "Modify" class= "btn" ><input type= "button" value= "delete" class= "btn"  ></td >                            </tr>                        <?php Endforeach?>  

All users of the background administrator are listed by using the foreach () function.

And $rows is a function: (in admin/listadmin.php)

<?phpinclude '. /include.php '; $rows =getalladmin (), if (! $rows) {alertmes ("Sorry, no administrator, add!", "addadmin.php"); exit;}? >

The Getalladmin () function is: (in core/admin.inc.php)

function Getalladmin () {$sql = "Select Id,username,email from Imooc_admin"; $rows =fetchall ($sql); return $rows;}

The function of Fetchall () is: (in lib/mysql.func.php)

function Fetchall ($sql, $result _type=mysql_assoc) {$result =mysql_query ($sql), while (@ $row =mysql_fetch_array ($ result, $result _type)) {$rows []= $row;} return $rows;}
Alertmes () function: (in lib/common.func.php)
<?phpfunction alertmes ($mes, $url) {echo "<script>alert (' {$mes} ');</script>"; echo "<script> Window.location= ' {$url} ';</script> ';}? >

This is in the Learning MU lesson Network "Hand call You do e-commerce background website development" See, the teacher's code logic is really very good.

Get all the information from a list of data using foreach

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.