www.webdeveloper.com
Results 1 to 12 of 12

Thread: Would this work?

  1. #1
    Join Date
    Aug 2009
    Location
    Louisiana, U.S.A.
    Posts
    41

    Would this work?

    I'm trying to get the topics data table from my forum's MySQL database fed onto my website.

    I went into the PhpMyAdmin and I changed the SQL code of the base to PHP and got this:

    PHP Code:
    $sql 'SELECT * FROM `forums_topics` LIMIT 0, 30 '
    I don't know much about PHP, but I've seen it alot, so I took a guess at how to implement it into my site.
    Here's what I did:

    PHP Code:
    <?php 

    $sql 
    'SELECT * FROM `forums_topics` LIMIT 0, 30 '

    ?>

    But whatever code that is in the section that I want the feed to be in has to be in between <li></li> tags, and I do not know how to put those into PHP, which is what I'm assuming is making the above code not work.

    What happens is just a "." where the feed should be.

    Does anyone know if this is the problem, and if so, how can I fix it?

  2. #2
    Join Date
    Jul 2007
    Posts
    58
    Hi,

    The code you have added just constructs the query, after it you will have to execute it, get the result returned in an array and then run a while loop or foreach on this array to populate the <li>.

    Hope this helps.

    Cheers,

    ~Maneet
    Maneet Puri

  3. #3
    Join Date
    Apr 2008
    Location
    UK
    Posts
    76
    This page should help you.

    Check out the page example.

  4. #4
    Join Date
    Aug 2009
    Location
    Louisiana, U.S.A.
    Posts
    41
    Alright, I used the example on the page and edited everything I could find.
    What do I have to put as my row? Because I think I'm getting my rows and columns mixed up. Because when I try to run this, it shows me this:

    Code:
    No rows found, nothing to print, so am exiting

    Here is the code I'm currently using:


    PHP Code:
    <?php

    $conn 
    mysql_connect("localhost""ashint_cn""********");

    if (!
    $conn) {
        echo 
    "Unable to connect to DB: " mysql_error();
        exit;
    }
      
    if (!
    mysql_select_db("ashint_forums")) {
        echo 
    "Unable to select mydbname: " mysql_error();
        exit;
    }

    $sql "SELECT title as title 
            FROM   forums_topics
            WHERE  title = 1"
    ;

    $result mysql_query($sql);

    if (!
    $result) {
        echo 
    "Could not successfully run query ($sql) from DB: " mysql_error();
        exit;
    }

    if (
    mysql_num_rows($result) == 0) {
        echo 
    "No rows found, nothing to print, so am exiting";
        exit;
    }

    // While a row of data exists, put that row in $row as an associative array
    // Note: If you're expecting just one row, no need to use a loop
    // Note: If you put extract($row); inside the following loop, you'll
    //       then create $userid, $fullname, and $userstatus
    while ($row mysql_fetch_assoc($result)) {
        echo 
    $row["title"];
    }

    mysql_free_result($result);

    ?>

    Please note, my password is not actually 8 stars.

  5. #5
    Join Date
    Jan 2009
    Posts
    3,346
    Do you have any data in the database to query?

  6. #6
    Join Date
    Aug 2009
    Location
    Louisiana, U.S.A.
    Posts
    41
    Yes, I'm trying to query my recent topics posted and there are 4 topics in the database. I'm thinking I'm just putting the wrong queries in the code

  7. #7
    Join Date
    Oct 2005
    Posts
    843
    most likely the problem is your query, so try changing it to:
    PHP Code:
    $sql "SELECT * FROM forums_topics ORDER BY insert_here DESC LIMIT 4"
    change the "insert_here" in the query to something like an id for the table or a date so it will pull the most 4 more recent from the table.
    Welsh

  8. #8
    Join Date
    Aug 2009
    Location
    Louisiana, U.S.A.
    Posts
    41
    Wow, that actually worked. Thanks alot!
    Now the only problem is it comes out like this:

    Code:
    Windows 7Snow Leopard is here!Instant Messaging....Advertising Video
    While it should actually show like this:

    Code:
    Windows 7
    Snow Leopard is here!
    Instant Messaging....
    Advertising Video

  9. #9
    Join Date
    Jan 2009
    Posts
    3,346
    change this:
    PHP Code:
    echo $row["title"]; 
    to:
    PHP Code:
    echo $row["title"]."<br />"

  10. #10
    Join Date
    Aug 2009
    Location
    Louisiana, U.S.A.
    Posts
    41
    Ah, thank you again!

    Now, another problem. How can I link them to the actual post?
    Last edited by poker158149; 09-05-2009 at 11:26 PM.

  11. #11
    Join Date
    Oct 2005
    Posts
    843
    PHP Code:
    echo $row["title"]."<br />"
    to
    PHP Code:
    echo '<a href="link.php">' $row['title'] . '</a><br />' 
    is the default thing, however im not sure what the url up top shows as, im guessing it would be like yourwebsite.com/forum/showthread.php?t=1234 so then assuming t is like the column id then it would be:
    PHP Code:
    echo '<a href="yourwebsite.com/forum/showthread.php?t=' $row['id'] . '">' $row['title'] . '</a><br />' 
    Welsh

  12. #12
    Join Date
    Aug 2009
    Location
    Louisiana, U.S.A.
    Posts
    41
    You are a god. Thank you so much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles