0

hello
i have an attribute in 'users' table called RegNo which refer ro region number ...
so i have to select users and display them according to their region number .

here is my code

<body>

<ul id="nav">
<li class="heb"> <a href="parentUrl" >hebron</a>
<li class="bet"> <a href="parentUrl" >ramallah</a>
<?php
include ("config.php");
$query="select * from users";
$returnValue=mysql_query($query,$connect);
if (!$returnValue)
    die ("error");
else
    {
        while($row=mysql_fetch_array($returnValue)){
        if ($row['RegNo']==100){
            echo '<ul class="heb">
                       <li><a href="childAUrl" >'.$row['username'].'</a></li>
                    </ul>
                ';
            }   
        }
    }
?>
</li>
</li>
</ul>

so if the RegNo=100 , username must be displayed under 'hebron' city...

how i can solve this problem ?!

Edited by m1m6jbr

3
Contributors
9
Replies
44
Views
3 Years
Discussion Span
Last Post by m1m6jbr
0

You need to order the records by RegNo.

In your loop, listen out for a change in the regno value. if it changes, that's a trigger to place a "heading" before adding individual list items

0

you mean if there are any change in regno , i must dispaly the heading (<li class="heb"> <a href="parentUrl" >hebron</a>)
, and then add individual items ?!

0

I have no idea.

If you order your data by regno, then in your data loop, you listen out for when the regno changes. You didn't put a WHERE clause in your SQL, so I'm assuming that you're outputting every single user in the table.

Not quite sure what you're trying to do. Are you just tring to return users for one 'selected' city?

0

output must be for more than one city

like

hebron
    user1
    user2
jenin
    user3
    user4
0

What are your table fields? How is the city name retrieved? I assumed that RegNo was the id for city. So, we need to know the table fields and maybe a row or two as example data

0

here's my table attributes

username    password    UserId  Email   Phone   RegNo

UserId is the primary key

Ex data :
username    password    UserId  Email   Phone   RegNo
john        123456WSD   8542WQ  s@s.xom 52154   100 

sami        10223       5542WQ  s@s.xom 52154   101

jojo        032656      8582WQ  s@s.xom 52154   102
0

Your requirement is just grouping, its does not look like tree

You can do this using two queries

$cityquery= "select distinct city from usertable"
loop -- through above records and in loop fetch users for the city
echo $cityrow['city']
$userquery "select usernaem from usertable where city='{$cityrow['city']}'";

loop
   echo "&nbsp;&nbsp;&nbsp;".$userrow['userid'];
end loop

end loop ---city

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.