开发者

PHP MYSQL : now I am fed-up with the same warning

I tried every thing in below code but I am not at all able to arrange resulted table in ascending order. This time I am getting the table but not in arranged order and also two warnings. My code is as follows:

     <?PHP 

         require_once("lib/connection.php"); 
         $array = array();
         $result = mysql_query("SHOW TABLES FROM st_db_1");
         while($row = mysql_fetch_row($result) ){
         $result_tb = mysql_query("SELECT id FROM $row[0] LIMIT 1");
         $row_tb=mysql_fetch_array($result_tb);
         $array = $row[0];

        echo "{$row[0]}<br/>" ;
         }
    sort($array);
    foreach ($array as $item) {
        echo $item;
    }
   ?>

And the output I am getting is below :

 class_1
 class_10
 class_11
 class_12
 class_2
 class_3
 class_4
 class_5
 class_6
 class_7
 class_8
 class_9

  ( ! ) Warning: sort() expects parameter 1 to be array, string given in C:\wamp\www\Copy (4) of st_db_1\test_2开发者_如何学运维.php on line 15

Call Stack

  ( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp\www\Copy (4) of      st_db_1\test_2.php on line 1 call Stack

But I want output in the below mentioned order:

 class_1
 class_2
 class_3
 class_4
 class_5
 class_6
 class_7
 class_8
 class_9
 class_10
 class_11
 class_12

Please help.


use $array[] = $row[0]; instead of using $array = $row[0];

$row[0] is a string, and yo are over-writing $array with the string. Thats why $array is a string not array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜