By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

Styling php generated menu items

P: 3
I am bidding on a project that was coded completely in php with basic tables containing the data. My job is to make the site look pretty. I am a designer and I can *read* the php, but am not the person to generate or tweak code.

I can generate the CSS styling to do the bulk of the design, but am running in circles trying to figure out how to style this output successfully:
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $sql = "select * from masterCategory";
  3. $masterResult = mysql_query($sql);
  4. while ($mr = mysql_fetch_array($masterResult)){
  5.     echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  6.     echo "<font color=\"#FFFFFF\" size=\"+1\">".$mr["name"]."</font><br>";
  7.     $sql = "SELECT * FROM category where masterid = ".$mr["id"]." ORDER BY id";
  8.     $result = mysql_query($sql);
  9.     While($r = mysql_fetch_array($result)){
  10.         echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  11.         echo "<A href=\"preview.php?cat=".$r["id"]."\">".$r["name"]."</A><br>";
  12.     }
  13.     echo "<br>";
  14. }
  15.  
  16.  
  17. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]

The client determines the mastercategories (3 at the moment) and there are varying numbers of names under each mastercategory.

Here is the way I would like it to look:

Master 1
some1
some2
some 3
Master 2
some 1
some 2
some 3

I can style the list once I learn how I can it recognize each piece of the list as generated by the php. I prefer not to do &nbsp inserts all over the place :>)

My undying gratitude to you who can provide the solution!
Jun 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: 93
I don't fully understand what you're trying to do... do you want to put it all into a table? Or just have each name/link on a new line? What are all the &nbsp;s for? I know what they do, but surely they are just indenting everything?

As far as I can see the data should get printed out like you said. Well actually like (indented by all the &nbsp;s):

Master 1
www.name1.com
www.name2.com
Master 2
www.name1.com
www.name2.com

A quick explanation of your php code (not sure what *read* means!):
Lines 1 and 2 get all of the master categories from your database.
And then lines 4-12 say:
for each one of the master categories -
print lots of &nbsp; and print the category name.
And then get from the database all of the records that match that category,
and for each of the matching records
print lots of &nbsp;
and print the link for it.

I hope something in that helps!...?
(Ok, so that ddn't actually come out indented anyway!)
Jun 2 '07 #2

P: 3
The info that is produced now is the menu system for the site. When it displays now, (see www.refrazegame.com) the main headings are in white and the subcategories are a yellow. Body of text is black. I was able to do that much applying some CSS to the pages. The person who coded the pages, used the html code to insert spaces. I want this to be a list format styled with CSS but am unsure of how to "define" the subcategories as the php generates them. I left the "spaces" that the original coder put in to make the categories line up. I want to remove those and use pure CSS to say this is a list.

Here is the current code:



<ul><!--Attempt to use list function -->
[PHP]<?
echo "<li>";
$sql = "select * from masterCategory";
echo "</li>", "</ul>";
$masterResult = mysql_query($sql);
while ($mr = mysql_fetch_array($masterResult)){

echo "<font color=\"#FFFFFF\" size=\"+1\">".$mr["name"]."</font><br>";
echo "<ul>","<li>";
$sql = "SELECT * FROM category where masterid = ".$mr["id"]." ORDER BY id";
$result = mysql_query($sql);
While($r = mysql_fetch_array($result)){

echo "<A href=\"preview.php?cat=".$r["id"]."\">".$r["name"]."</A><br>";
}

echo"</li>";

echo "<br>";
}


?>
[/PHP]</ul> <!-- moved the end of the listing AFTER the preview code -->

But, using this method, I just get too many indents. Please see:
listing go awry

Do I just insert echo <li> </li> for each line of generated subcategories? I know I can keep playing with it until I find what works, but I was hoping to spend some time on the proposal :>)
Am I making this too complicated?


I don't fully understand what you're trying to do... do you want to put it all into a table? Or just have each name/link on a new line? What are all the &nbsp;s for? I know what they do, but surely they are just indenting everything?

As far as I can see the data should get printed out like you said. Well actually like (indented by all the &nbsp;s):

Master 1
www.name1.com
www.name2.com
Master 2
www.name1.com
www.name2.com

A quick explanation of your php code (not sure what *read* means!):
Lines 1 and 2 get all of the master categories from your database.
And then lines 4-12 say:
for each one of the master categories -
print lots of &nbsp; and print the category name.
And then get from the database all of the records that match that category,
and for each of the matching records
print lots of &nbsp;
and print the link for it.

I hope something in that helps!...?
(Ok, so that ddn't actually come out indented anyway!)
Jun 4 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.