Jump to content

Php and li


mclard

Recommended Posts

Hi,

I have a mysql database containing 100 records, some of these records have a 'position' against them.

Im trying to get the following result....

1. A list containing 100 entries.

2. If li 1 has a 'position' against it, data is entered from the database, or it has default text, this is to carry on to li 100.

 

What ive got so far follows

$i = 1;
if ($i<=100) { 
$SQL = "SELECT * FROM ws WHERE location ='$data' AND position ='$i'";
$result = mysql_query($SQL);   
while ($row=mysql_fetch_array($result)) {
echo "<div><ul id='$i'>";
echo "<li id='$row[0]'>$row[4]</li>";
echo "</ul></div>";
}
$i++;
} else {
echo "????";
}

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/112549-php-and-li/
Share on other sites

If i use

$i = 1;
if ($i<=100) {  
$SQL = "SELECT * FROM ws WHERE location ='$data' and position ='$i'";
$result = mysql_query($SQL); 
while ($row=mysql_fetch_array($result)) {
if ($row[4] == '$i') {
echo "<div><ul id='$i'><li id='$row[0]'>$row[4]</li></ul></div>";
} else {
echo "<div><ul id='$i'></ul></div>";
}
}
$i++;
}

 

I get some output but not the right one...

 

What i get in the page source is

<div><ul id='1'></ul></div>
<div><ul id='1'></ul></div>

And what id hope to get is

<div><ul id='1'><li></li></ul></div>
<div><ul id='2'><li>2</li></ul></div>
<div><ul id='3'><li></li></ul></div>
<div><ul id='4'><li>4</li></ul></div>

Thanks

Link to comment
https://forums.phpfreaks.com/topic/112549-php-and-li/#findComment-578062
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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