Jump to content

<UL> and <LI> using php


adman4054

Recommended Posts

I've searched Google and can quite get this to work after hours of searching.

 

I'm trying to use an unordered list. Like this:

<ul id="demoOne" class="demo">
    <li class="ln-_" style= "display: none;"> <a href="#"> 411 Services </a> <li>
    <li class="ln-a;"> <a href="#"> Adams </a> <li>
    <li class="ln-z;"> <a href="#"> fake </a> <li>
</ul>

Using this code, I cant get the <UL> to only appear once in the code. Can I still use "echo" when trying to use the above?

while($company = mysql_fetch_array($query)) {
								
echo "<tr><td width='125' class='bodyTxt'>". $company['t2'] ." </td><td class='bodyTxt'><a href='CompanyContact.php?companyID=".$company['t2']. "'class='adminLink'>" . "<li>" . $company['t1'] ." </li></a></td></tr>";

As shown in the above code, I need $company[t1] to be the list itself (<li>company a </li> under the <ul> as shown in my first code block.) $company [t2] is just a number and needs to appear with [t1], but isn't part of the <li> list.

 

Any help is appreciated

 

Thanks

 

Query

include("../inc/conn.php");		  
				//$query = mysql_query("SELECT company.companyName t1, company.companyID t2, companycontact.contactID t3 from company, companycontact where company.companyID=companycontact.companyID ORDER BY company.companyName");
				
				$query = mysql_query("SELECT company.companyName t1, company.companyID t2 from company ORDER BY company.companyName");
				$num_rows=mysql_num_rows($query);  
Link to comment
Share on other sites

I'm not sure that I understand the question, but I think what you want is:


echo '<ul class=...."';//note outside while loop
while($company = mysql_fetch_array($query)) {
								
echo "<li> <a href=\"#\" >" . $company['t1'] ." </li></a>\n";
}
echo '</ul>';//note outside while loop
Link to comment
Share on other sites

Note that the close </a> tag needs to go inside the close </li> tag.

<?php
echo '<ul class=...."';
while($company = mysql_fetch_array($query)) {
     echo "<li><a href=\"#\">" . $company['t1'] . "</a></li>"; //<-- NOTE: close </a> tag was moved inside the close </li> tag
}
echo '</ul>';
?>
Link to comment
Share on other sites

So when I look at the source when putting the code outside the loop, it says "Start <ul> inside a table.." in red, so I assume I need to place that outside the table that Ch0cu3r was asking? The entire page is "tableized" (dont think that is a real word, but......). any place else I put it, it doesn't start with the <ul>

 

I'm using a jquery called ListNav and it isnt picking up the structure that it needs to work;

 

ul id="demoOne" class="demo">
<li class="ln-_" style= "display: none;"> <a href="#"> 411 Services </a> <li>
<li class="ln-a;"> <a href="#"> Adams </a> <li>
<li class="ln-z;"> <a href="#"> fake </a> <li>
</ul>

 

So do I need to somehow get rid of the tables for this to work? Appreciate the time :)

Link to comment
Share on other sites

No, no you can have a  list within a table, along as it is in a table cell (<td></td>).

<table>
  <tr>
    <td>
      text
      <ul>
        <li>item 1</li>
        <li>item 2</li>
      </ul>
    </td>
  </tr>
    ....
</table>

The way how you are describing your problem is you're wanting the list to do something like this

<ul>
<table>
   <tr>
      <td> text <li>item 1</li></td>
   </tr>
   <tr>
      <td> another <li>item 2</li></td>
   </tr>
</table>
</ul>

Which you cant do.

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.