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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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