views:

357

answers:

4

Quick question, again, I'm sure this is ridiculously simple but I don't see what I'm doing wrong!

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))

{
echo  "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a>";
}

This produces all my links to be stacked up one after the other. I want to order them in a list so I have tried:

echo "<ul>";

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))

{
echo  "<li><a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']}    </a> </li>";
}
echo "</ul>" ;

and

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))

{
echo  "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']}    </a> <br />";
}

The ultimate result I wish to see is :
-Link 1
-Link 2
-Link 3
-Link 4
What am I doing wrong? Thanks in advance!

A: 

For a line break in HTML try using <br />, your code can look like something along this line:

echo "<ul>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))

{ 
echo  "<li><a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']}</a></li> <br />";
}
echo "</ul>";

EDIT

Also note, as mentioned before in the comments, <br /> isn't needed, if I take it out of my code my output stays the same.

I made a test php file similar and used my suggestion above and works fine, here is my code

<?php
echo "<ul>";
$i = 0;
do {
$i++;
echo  "<li><a href=\"http://mysite.com/{$i}/{$i} \">{$i}</a></li> <br />";
} while($i < 10);
echo "</ul>";
?>

Displayed below:

See

Anthony Forloney
Not downvoting, but when using `<ul><li>...</li><li></li></ul>` you should not be needing a `<br />` in there.
ChristopheD
`<li>` doesn't make sense in this context (and is invalid without `<ul>` or `<ol>`)
Marek Karbarz
Of course it makes sense: It's a *list* of links, so `<li>` (within `<ul>` or `<ol>`) is the *only* semantically correct way to write this.
Heinzi
this post has been edited - original had no `<ul>` around it
Marek Karbarz
Sorry everyone, I edited my original post, I didn't mean to have a <li> in the 3rd example, as I had tried that one simply as a <br/>, seeing that the <ul><li></li></ul> option had no effect!
skarama
Should I use <li> AND a <br/>?
skarama
@aforloney - I think you're missing the intention of the curly brackets in this case
Marek Karbarz
I am trying an example code right now using <li> and <br /> and either or works just fine for me
Anthony Forloney
@Marek K - I wouldn't doubt it, didn't think before I edited.
Anthony Forloney
Thanks everyone, I also did a test in a different section, they both work fine. I was trying to do this in a Joomla module, there is probably something stripping away these tags.
skarama
Good luck in the future :)
Anthony Forloney
A: 

I can't spot anything wrong with it. Even a <br/> should work:

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo  "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a><br/>";
}
Amarghosh
Oops sorry, that's what my third example should have been. I did try this as well, and still to no avail. What's extra weird to know, if this can help, is that when I look view-source this region of my page, adding the <br /> has an effect on my source's alignment of the links. Basically, instead of seeing a <br/> tag, I see its effect being applied into the source, creating the wanted lien break but not visible on the site itself?!
skarama
A: 

use echo "<a href="…>link</a>\n to add a newline in the generated sourcecode

knittl
Tried that, to no avail either :(
skarama
A: 

Try this

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$layout .= "<div style='display:block;'><a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']}</a></div>";
}

echo $layout;
RSK
Very nice idea, still no result. It actually stacks up all my links without even a space in between them!
skarama
I am still confused how you like to display the result.
RSK
Edited my original post to show you, hope it helps!
skarama