1

I have a list of urls that I need to echo from my "menu" table. Here is what I have so far, but I can't seem to figure out the rest of it. The urls below are obviously there to show the format of the original HTML.

<?php

    $results = mysql_query("SELECT * FROM menu WHERE level='$level'");
    $row = mysql_fetch_array($results);

    ?>
        <li><a href="http://website.com/webservices/admin/achievments.php" target="ifrm">Achievments</a></li>
        <li><a href="http://website.com/webservices/admin/avatar.php" target="ifrm">Avatar</a></li>

.... more urls ....
2
  • could you show us the table structure Commented May 5, 2011 at 16:30
  • I'm pretty sure they were all correct. nomaD's answer was most comfortable for me. Thanks guys. Commented May 5, 2011 at 17:00

3 Answers 3

2

You need to do it in a loop, usually a while loop:

<?php

$results = mysql_query("SELECT * FROM menu WHERE level='$level'");
while ($row = mysql_fetch_array($results)) {
    echo'<li><a href="'.$row['uri'].'" target="ifrm">'.$row['name'].'</a></li>';
}
?>

I've improvised on your column names (uri and name), they will probably be something different.

Sign up to request clarification or add additional context in comments.

Comments

0

Close. Personally I would use put it into a while loop to read all the values. then echo them one by one.

while($row = mysql_fetch_array($results)){
echo "<a href = \"". $row['fieldtouse'] . "\" />". $row['textforlink'] . "<a/>";
}

That is the idea. Loop through results. echo results.

Comments

0

I believe this is a simple case of iterating over the result list. And as you already mentioned you should not use a single mysql_fetch_array, but in a loop like this:

while ($row = mysql_fetch_array($results)) {

    print "<li><a href='.../$row[0]' target='evil'>$row[1]</a></li>";

}

Now $row[0] and $row[1] will have to be adapted. Prefer mysql_fetch_assoc to get named result columns, and then apply e.g. $row[url] and $row[title] instead of the numeric keys.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.