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 Quote Link to comment Share on other sites More sharing options...
ThLoser Posted June 25, 2013 Share Posted June 25, 2013 use SORT BY jobs in SQL? Quote Link to comment Share on other sites More sharing options...
l3rodey Posted June 26, 2013 Share Posted June 26, 2013 (edited) 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. Edited June 26, 2013 by l3rodey Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.