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
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.

Edited by l3rodey
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.