Jump to content

Skorpio

Members
  • Content Count

    52
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Skorpio

  • Rank
    Regular Member
  1. I hadn't thought of any alternatives other than return and echo the function which I have now, function navmenu($db){ $data = $db->query("SELECT * FROM menu")->fetchAll(PDO::FETCH_ASSOC); foreach ($data as $row) { return "<li><a href='{$row['url']}' title='{$row['title']}'><i class='{$row['icon']}'></i> {$row['header']}</a></li>"; } } then // Navigation Menu Function echo navmenu($db);
  2. Thanks, when I put in the additional $row information I again added too many quotes. This has solved the issue which has resulted in the following code foreach ($data as $row) { echo "<li><a href='{$row['url']}' title='{$row['title']}'><i class='{$row['icon']}'></i> {$row['header']}</a></li>"; } If I use the quotes around the {$row['header']} -> '{$row['header']}' they print out on screen. Removing the 2 single quotes has solved the issue and when I view source I get the following <li><a href='?page=home' title='Home Page'><
  3. Thanks for this however as I say I want to put the whole navigation code block into a function so the closing a and li would be an issue. From trying the code I get
  4. Thanks for this. It gives me part of the solution however I get the echo and quotes printed on screen. When I look at the colour coding in brackets the closing single quote, square bracket and closing brace are highlighted in red
  5. I have a navigation list displaying which is a mix of html and php, everything is working fine however now I want to convert this block of code into a function but am having major problems with quotes. The line of code I currently have is $data = $db->query("SELECT * FROM menu")->fetchAll(PDO::FETCH_ASSOC); foreach ($data as $row) { ?> <li><a href="<?php echo $row['url']; ?>" title="<?php echo $row['title']; ?>"><?php echo $row['icon'] . ' ' . $row['header']; ?></a></li> <?php } ?> As I say everything works using the
  6. I am trying to resolve the initial problem, getting nowhere fast. so it should read $ As the variable is storing all data records? So Should read foreach ($row as $rows){ Is that what you are meaning requinix? The foreach that I am using in the 2nd example works as far as the navigation however I cannot include the content for the page within the foreach which makes the join redundant. I am unsure what the solution is to this but I feel as though I am going round in circles. The above, my first code with the foreach loop would present m
  7. Although still looking to resolve the issue with my php above I am looking at other solutions. Although the followi8ng code populates my navigation menu correctly I am unable to get the page data to sync with the appropriate navigation choice. $sql= "SELECT * FROM menu LEFT JOIN pages ON menu.id = pages.page_id"; $stmt = $db->query($sql); $row = $stmt->fetchAll(PDO::FETCH_ASSOC); // To print array out echo "<pre>"; print_r($row); echo "</pre>"; Then where the navigation is I have <?php for
  8. What is? As I say the SQL is working, it is the PHP thats the issue.
  9. Hi I have a 4 button navigation, home, projects, about and contact. This is in one table, menu, this table has the relevant icon to display with the appropriate link and another field is the link itself, ?page=home. Menu is joined with the pages table using the following query SELECT * FROM menu LEFT JOIN pages ON menu.id = pages.page_id When I run this through phpmyadmin sql console everything is returned as expected, all pages match up with the navigation. When I print_r($row); all 4 fields from the nav table and all 7 fields from the pages table, totalling 11 fields, displa
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.