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 ?!

Member Avatar for diafol

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

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 ?!

Member Avatar for diafol

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?

output must be for more than one city

like

hebron
    user1
    user2
jenin
    user3
    user4
Member Avatar for diafol

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

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

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

aha thanks :)
i will try....

done :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.