Results 1 to 5 of 5

Thread: Sql & php

  1. #1
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sql & php

    I'm brand new to this. I want to set up a sql database, but then display the results, along with the links to point to that page. Another question I have is, is there a way instead of creating each individual webpages (links) to have a tamplate where the results from the database be automatically generated into a webpage?

  2. #2
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default Sql & php

    Well it doesnt seem like anybody is giving you a try, so i will.

    Are you trying to build a navigation menu or something?

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Depends on how you've layed out your code so far, but you'll want to make good use of:

    Code:
    $query = mysql_query("SELECT * FROM table");
    
    while($row = mysql_fetch_array($query))
    {
    echo $row['links'];
    }
    Obviously that's very basic but then using "include" you can include a template with links on it that you want and have it cascade across all pages.

  4. #4
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default Sql & php

    Yeah thats pretty much what i was thinking when building the menu.
    Maybe you can make it into a table.

    Ex.

    PHP Code:
    <?php
    //conection
    $query mysql_query("SELECT * FROM table");

    while(
    $row mysql_fetch_array($query))
    {
    echo
    "
    <table width='100%' border='0' cellpadding='0' cellspacing='0'>
    <tr>
    <td><a href="
    \". $row['link1'].""\>Link 1</a></td>
    <td><a href="
    \". $row['link2'].""\>Link 2</a></td>
    </tr>
    </table>"
    ;
    }
    ?>
    Or you could just make the links in a seperate php file and include it into your page so that way you dont have to deal with mysql and it makes it easier to change the links.

    PHP Code:
    <?php
    echo"
    <table width='100%' border='0' cellpadding='0' cellspacing='0'>
    <tr>
    <td><a href='www.google.com'>Link 1</a></td>
    <td><a href='www.dynamicdrive.com'>Link 2</a></td>
    </tr>
    </table>"
    ;
    ?>

  5. #5
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default

    i know i put "\" after the href.... <a href ="\" in the first box

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •