wearekda Posted June 25, 2013 Share Posted June 25, 2013 Hello everybody,I am new to php, I have created a table in my database it's name is users the table contains name of the user and his job, I want to create a php page that shows me the same jobs in a row and the other same jobs in another row for example Jhon=doctor Mark=engineer Kevin=engineer Alex=teacher Dani=doctor Adam=teacher and the result Dr. Eng. Mr. Jhon Mark Alex Dani Kevin Adam So how to make it? Thanks Link to comment https://forums.phpfreaks.com/topic/279577-select-from-a-table-the-same-fields/ Share on other sites More sharing options...
ThLoser Posted June 25, 2013 Share Posted June 25, 2013 use SORT BY jobs in SQL? Link to comment https://forums.phpfreaks.com/topic/279577-select-from-a-table-the-same-fields/#findComment-1437888 Share on other sites More sharing options...
l3rodey Posted June 26, 2013 Share Posted June 26, 2013 mysql_query or mssql_query depending on your database if it's mysql or micosoft sql for this demo I will us MySQL. <table> <tr> <td>MR</td> <td>Teacher</td> <td>Dr</td> </tr> <tr> <?php $query = mysql_query("SELECT * FROM users WHERE job='Mr' ORDER BY name"); while($row = mysql_fetch_array($collect_folders)){ $name = $row['name']; echo '<td>' . $name . '</td>'; } ?> <?php $query = mysql_query("SELECT * FROM users WHERE job='Teacher' ORDER BY name"); while($row = mysql_fetch_array($collect_folders)){ $name = $row['name']; echo '<td>' . $name . '</td>'; } ?> <?php $query = mysql_query("SELECT * FROM users WHERE job='Dr' ORDER BY name"); while($row = mysql_fetch_array($collect_folders)){ $name = $row['name']; echo '<td>' . $name . '</td>'; } ?> </tr> </table> You will need to make heaps of changes but this will work, surely someone has something better but this does the trick. Link to comment https://forums.phpfreaks.com/topic/279577-select-from-a-table-the-same-fields/#findComment-1437897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.