Jump to content

Select from a table the same fields.


wearekda

Recommended Posts

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 

 

:D

Link to comment
https://forums.phpfreaks.com/topic/279577-select-from-a-table-the-same-fields/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.