Dear devolepers,
I have problem with my sql database, I want acces my sql database in my <LI> list plaese help to resolve this problem
Here is my html
sql database : my_db
table : info_list
Table columns :
id,name,job,town,mobile1,mobile2,phone,adress

i want to display town list in this <li> list

<div id="choisir_ville" data-role="page" data-add-back-btn="true">

<div data-role="header"> 
    <h1>  Info</h1>
</div> 
<div data-role="content">
<div class="choice_list"> 
<h1>Select your nearest place? </h1>
<ul data-role="listview" data-inset="true" data-filter="true"  >
<li><a href="choose_worker.php"  data-transition="slidedown"> Nilambur <span class="ui-li-count" > 3 </span></a> </li>
<li><a href="choose_worker.php"  data-transition="slidedown"> Chandakunnu<span class="ui-li-count" > 2 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">  Vadapuram<span class="ui-li-count" > 5 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown"> Mampad<span class="ui-li-count" > 1</span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Wandoor<span class="ui-li-count" > 2</span></a> </li>   
<li><a href="choose_worker.php" data-transition="slidedown">Pokkottumpadam<span class="ui-li-count" > 2</span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Karulai<span class="ui-li-count" > 10 </span></a> </li> 
<li><a href="choose_worker.php" data-transition="slidedown">Moothedam<span class="ui-li-count" > 8 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Edakkara<span class="ui-li-count" > 1 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Vazhikkadavu <span class="ui-li-count" > 3 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Marutha<span class="ui-li-count" > 2 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Pothukallu<span class="ui-li-count" > 4 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Akampadam <span class="ui-li-count" > 6 </span></a> </li>
<li><a href="choose_worker.php" data-transition="slidedown">Erumamunda<span class="ui-li-count" > 2 </span></a> </li>
<li><a style="text-align: center" href="index.php" data-transition="slidedown">Back to Home </a> </li>
</ul>
</div>
</div>

</div><!-- /page -->

Hi,

so you want to group the names under each town? For example:

<ul>
    <li>Town
        <ul>
            <li>Name X</li>
            <li>Name Y</li>
            <li>Name Z</li>
        </ul>
    </li>
    ...
</ul>

is this correct?

yes from my database, and while clicking particular town I want to show the same town extract list (town wise filter)

Ok, then you could use PDO to group the results into an array, the index key is defined by the first column listed in the SELECT statement, in your case it will be the town column.

Here's an example:

$conn = new PDO('mysql:host=localhost;dbname=my_db', 'username', 'password');
$stmt = $conn->prepare('SELECT `town`, `il`.* FROM `info_list` AS `il` ORDER BY `town`, `name` ASC');
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_OBJ);

Then create a template for the list:

$list     = '';
$template = '<li>%s<ul>%s</ul></li>';

And loop the results:

foreach($rows as $town => $value)
{
    $li = '';
    foreach($value as $row)
        $li .= "<li>$row->name, $row->job</li>";

    $list .= sprintf($template, $town, $li);
}

Then into your HTML simply do:

<ul>
<?php echo $list; ?>
</ul>

More info here: http://php.net/manual/en/pdostatement.fetchall.php

Sorry for inconvenience, I got better and simple way

<?php
$con=mysqli_connect("localhost","user","pass","mydb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM n_info ");

while($row = mysqli_fetch_array($result))
{
echo "<ul class='ui-listview ui-listview-inset ui-corner-all ui-shadow';  >";
echo "<li data-theme='c'; class='ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-count ui-btn-up-c';><div class='ui-btn-inner ui-li';><div class='ui-btn-text';><a href='choose_worker.php'; data-transition='slidedown'; class='ui-link-inherit';> " . $row['location'] . "<span class='ui-li-count ui-btn-up-c ui-btn-corner-all';>2 </span></a> </div><span class='ui-icon ui-icon-arrow-r ui-icon-shadow'></span></div></li>";
echo "</ul>";
}

mysqli_close($con);

?>

Good for you, bye! :)

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.