Show member with same column id

0

How do I display a list of members for each position, with some members being in more than one position. The categories where members meet, are in the same column separated by pipe ( | ).

Follow the image below:

Mycodeonlydisplaysthefirstid(8)forexample,incaseifIclickanotherpost,suchasid40,itdoesnotappearonthesite.Hereismycode:

<?php$id=isset($_GET['id'])?$_GET['id']:'';$newid=($id."|");
$sql = mysql_query("SELECT * FROM acp_usuarios u, acp_cargos t WHERE t.id=u.cargos AND u.id=t.user_id AND u.status='Ativo' AND u.ativado='s' AND u.cargos LIKE '$newid' OR u.cargos = '$newid' ORDER BY u.id");
while($ver = mysql_fetch_array($sql)){

?>
    
asked by anonymous 05.10.2017 / 17:49

2 answers

1

The ideal is to reformulate the database and create a table to associate the job with the user. But if you can not do this rework, you can dodge this problem as follows:

$id = isset($_GET['id']) ? $_GET['id'] : '';
$sql = mysql_query("SELECT * FROM acp_usuarios u, acp_cargos t WHERE t.id=u.cargos AND u.id=t.user_id AND u.status='Ativo' AND u.ativado='s' AND (u.cargos LIKE '%|$id|%' OR u.cargos LIKE '%|$id' OR u.cargos LIKE '$id|%') ORDER BY u.id");
while($ver = mysql_fetch_array($sql)){

}

The problem with doing this is that you will lose the speed of the query.

    
05.10.2017 / 19:42
2
LIKE '%$newid%'

The% indicates where you are looking for the result, when you use% $ newid% tells us that you are looking for the value of the variable in any column position.

Recommended Reading: link

    
05.10.2017 / 19:28