Question

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!

Was it helpful?

Solution

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

OTHER TIPS

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/>";
}

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

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top