Jump to content


Photo

<UL> and <LI> using php


  • Please log in to reply
9 replies to this topic

#1 adman4054

adman4054

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 07 April 2014 - 07:07 AM

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);  


#2 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,324 posts

Posted 07 April 2014 - 07:23 AM

411 Services, Adams and fake are example of companies? and you want all companies returned from your query to be in an unordered list? and not a table?



#3 davidannis

davidannis

    Freak Dr.

  • Members
  • PipPipPip
  • 610 posts
  • LocationOkemos, MI USA

Posted 07 April 2014 - 07:24 AM

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


#4 adman4054

adman4054

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 07 April 2014 - 07:46 AM

That makes perfect sense. It isn't working, but its doing exactly what I needed it to do. Thank you both for responding. :)



#5 cyberRobot

cyberRobot

    Advanced Member

  • Gurus
  • 1,758 posts

Posted 07 April 2014 - 08:05 AM

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>';
?>

Blogging about PHP and other web development topics at ScorpBytes.com

#6 adman4054

adman4054

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 07 April 2014 - 08:13 AM

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 :)



#7 adman4054

adman4054

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 07 April 2014 - 08:14 AM

Thank you cyberRobot!



#8 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,324 posts

Posted 07 April 2014 - 08:55 AM

You have not answered my question in my previous post.

 

It is not possible to have a <ul> list that spans multiple table cells and rows at the same time.



#9 adman4054

adman4054

    Advanced Member

  • Members
  • PipPipPip
  • 49 posts

Posted 07 April 2014 - 09:03 AM

Sorry Ch0cu3r, I wasn't aware the you cannot have a <ul> list in tables, but that makes sense. I do have the list within multiple tables, I'll try and sort that out. appreciate your post, thank you.



#10 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,324 posts

Posted 07 April 2014 - 09:21 AM

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com