php - Merge first column that has the same second column -


i have inner join query returns result:

first column | second column      2       |       15       5       |       16      6       |       16      5       |       18      6       |       22 

i want output them in page this:

first column | second column      2       |       15       5,6     |       16              |       18              |       22 total first column: 2 

it combine first column has same second column. , value of combined first column share between them.

and tell total first column (which in example 2).

i'm still trying code:

if($stmt = $con->prepare("select firsttb.firstcolumn, secondtb.secondcolumn firsttb inner join secondtb on firsttb.connectid = secondtb.connectid firsttb.getid = ? order secondtb.secondcolumn")){    $stmt->bind_param("i",$_get["getid"]);   $stmt->execute();   $stmt->bind_result($firstcolumn,$secondcolumn);    $lastid = 0;   $total = 0;   $combine = "";      while($stmt->fetch()){        if($lastid == $secondcolumn){         $combine = $combine."".$firstcolumn;         $lastid = $secondcolumn;       }        else {         $totalrow = $totalrow + 1;         $lastid = $secondcolumn;         $combine = $secondcolumn;          echo $combine." | ".$secondcolumn."<br>";        }      }   $stmt->close();   echo "total first column: ".$totalrow; } 

but output:

first column | second column      2       |       15       5       |       16      5       |       18      6       |       22 total first column: 4 

it okay scrap code , create own. want right idea.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -