mysql - Sorting table created by PHP, can't use query to sort -


i have column want sort. let me explain code first.

as can see, there 3 select statements , 3 different tables(table names in code). first query selects data table whereby assign retrieved data id column $device_id.

the second query selects data table according value of $device_id(one value only). return multiple board ids(multiple values). if rows returned, table created.

in table, third query executed check each board_id in third table($table_tester_info). if board_id exists, displayed. example: if there 40 board_id , out of 40 20 returned rows, rows displayed in table.

now here's problem. want sort table according column in $table_tester_info(the third table) however, can use order by in second query. wouldn't problem want sort according column in $table_tester_info, not $table_tester_config(the second table).

i'm using jquery not want use plugins sort dom elements in html unless there no other way(but i'm sure there many ways, don't know it). i've tried sorting assoc array(?) $tester_name or rather $final_row['tester_name'] assigned it.

curerntly table not sorted when add order by @ third query(which know wrong). on this?

<?php  // define database parameters define ('db_user' ,'iqwdewqe'); define ('db_password', 'iqadeaqwe'); define ('db_host', 'qadewe'); define ('db_name', 'tqweqwe');  // connect database @mysql_connect (db_host, db_user, db_password) or die ('could not connect'                   .'to database: '. mysql_error()); @mysql_select_db (db_name) or die ('could not select database: '. mysql_error());   function searchdevice($device_name, $tester_type) {     $table_device = "tbl_device_list";     $table_tester_config = "tbl_tester_config";     $table_tester_info = "tbl_tester_info";      $query_string = "select * $table_device device = '$device_name'                                 , tester_type = '$tester_type'";     $device_result = @mysql_query($query_string) or die (mysql_error());     $device_row = mysql_num_rows($device_result);      if($device_row)     {         $device_row = mysql_fetch_array($device_result);         $device_id = $device_row['id'];        // echo "device id: $device_id <br>";          $query_string = "select * $table_tester_config device_id = '$device_id'";         $config_result = @mysql_query($query_string) or die(mysql_error());         $config_row = mysql_num_rows($config_result);          if($config_row)         {               while($config_row = mysql_fetch_assoc($config_result))             {                 $board_id = $config_row['board_id'];                 $oboard = $config_row['configuration'];                  //echo "board id: $board_id <br>";                  //query check if board_id exists,                  if exists display value in while loop                 $query_string = "select * $table_tester_info                  board_id = '$board_id' order tester_name";                 $final_result = @mysql_query($query_string) or die(mysql_error());                 $final_row = mysql_num_rows($final_result);                      if($final_row)                     {                         echo "<table border='1'>";                         echo "<tr>                         <th>board id</th>                         <th>tester name</th>                         <th>board name</th>                         <th>configuration</th>                         <th>log created</th>                         <th>new</th>                         </tr>";                         while($final_row = mysql_fetch_assoc($final_result))                         {                             $board_id = $final_row['board_id'];                             $tester_name = $final_row['tester_name'];                             $board_name = $final_row['board_name'];                             $config = $final_row['config'];                             $log_created = $final_row['log_created'];                              echo "<tr>                                         <td>$board_id</td>                                         <td>$tester_name</td>                                         <td>$board_name</td>                                         <td>$config</td>                                         <td>$log_created</td>                                         <td>$oboard</td>                                      </tr>";                         }                     }             }             echo "</table>";         }     }     else     {         echo "no device name: $device_name tester type: $tester_type.";     } }  ?>  <?php  $action = rtrim($_request['action']);  if($action=="search") {     $device_name = rtrim($_request['device_name']);     $tester_type = rtrim($_request['tester_type']);      echo searchdevice($device_name, $tester_type); }  ?> 

combine queries 2 , 3 join. using inner join row if join successful.

ie:

select tti.* $table_tester_config ttc inner join $table_tester_info tti     on tti.board_id = ttc.board_id td.device = '$device_name' , td.tester_type = '$tester_type' order tti.tester_name 

then loop through results.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -