SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Milwaukee Wisconsin
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Entries not showing up in Blog

    Hello,
    I am creating a blog: http://adamb10.com/UltraBlog
    I am trying to make entries show but they won't Here are 2 files. The 1st file is index.php which grabs the data from mysql database and displays it:

    PHP Code:
    <?
    session_start
    ();
    include_once(
    "Sources/sys.php");
    ?>
    <html>

    <head>
    <meta http-equiv="Content-Language" content="en-us">

    <title>
    <?
    include '/home/adamb10/public_html/UltraBlog/Sources/mysqlconnect.php';
    $result mysql_query('SELECT title FROM Userdata') or die("Error: ".mysql_error());
    while (
    $row mysql_fetch_assoc($result))
    {
        echo 
    $row['title'];
    }
    echo
    '</title>
    <link rel="stylesheet" type="text/css" href="http://adamb10.com/UltraBlog/themes/style1.css"/>
    </head>'
    ;

    if(
    $action == "login"){
    return(
    '/Sources/sys.php');
    }
    if(
    $action == "acp"){
    return(
    '/Sources/sys.php');
    }
    if(
    $action == "settings"){
    return(
    '/Sources/sys.php');
    }
    if(
    $action == "about"){
    return(
    '/Sources/sys.php');
    }
    if(
    $action == "addentry"){
    return(
    '/Sources/sys.php');
    }
    if(
    $action == "editprofile"){
    return(
    '/Sources/sys.php');
    }
    if(
    $action == "hf"){
    return(
    '/Sources/sys.php');
    }
    echo
    '<body>
    <center><table width="80%" cellspacing="1" cellpadding="1" border="0" class="border">
    <td class="windowbg2" colspan="4"><center><font size="3"><b>Welcome to'
    ; echo $row['title'];
    echo 
    '</b></font></center>
    <tr>'
    ;
    ?>
    <?
    include '/home/adamb10/public_html/UltraBlog/Sources/urls.php';



    //Standard stuff that you already know how to do.  Make sure you use the @ before mysql_connect though,
    // if you don't and there's a problem, your password information will be displayed to everyone, it's
    // technically a good idea to write your own wrapper function for this so as to hide it from everyone
    // in all cases (ie: like if your host's PHP parsing suddenly died and all PHP were displayed as
    // plaintext to the world...you'd be showing your information yet again, for anyone to connect.  BAD!
    // By the way, the '@' symbol before any pre-written function allow any error messages NOT to be
    // displayed.  If you use this, be certain you'll never, ever have a problem, or only do it for
    // security reasons.  You won't want to use this during debugging (except for perhaps this line of
    // code, just because it's so simple, we still have the mysql_error function printing on error,
    // and something else I can't think of.  :)
    //Replace 'server' with your MySQL server location information, 'username' with your database server's
    // username for access, and password with your database server's password.  If you're using a different
    // database type (i.e.: Microsoft SQL Server), you will have to change the functions to suit your needs.
    // The SQL should still work, except for the LIMIT clause suggested within a comment - it is a MySQL
    // proprietary function.
    include '/home/adamb10/public_html/UltraBlog/Sources/mysqlconnect.php';

    //We needed to select the database that we'd be using...again, standard process.
    //mysql_select_db('adam', $cnx) or die('Could not connect to database: ' . mysql_error());

    //This SQL select statement will gather all information we should need for displaying your blog entries,
    // I use Entrys.Id and Userdata.Id here because when two tables contain the same field name, MySQL has
    // no idea which field belongs to which table.  We always use the tablename first, then the field in dot
    // notation.  Since the other fields do not have the same names, we can refer to them as normal.
    // I used the WHERE clause so that MySQL knows which blog entries are associated with which author, and
    // vice-versa.  I used the ORDER BY clause to make sure that we get the most recent entries first, as
    // most blogs that I've seen show the most recent entries first... If you want to change this, switch DESC
    // to ASC or vice-versa.  You can play around with those yourself.
    $sql 'SELECT entrys.Id, entrys.Date, entrys.Title, entrys.Entries, Userdata.Email FROM entrys, Userdata WHERE entrys.UserID=Userdata.Id ORDER BY Date DESC';

    //Time to actually run the SQL statement - it was only created on the above line (I think it's easier this way)
    $result mysql_query($sql) or die(mysql_error());

    //Now we want to break down this information into useable variables for display purposes...
    // However, we need to use a loop because the information stored in $result is something called a mysql
    // result resource (unless I'm thinking of $cnx)...anyhow, it's in an object/array style format and we
    // only want a portion at a time to work with, since ALL stories and users are returned.  Then we'll go
    // ahead and display each one separately.
    while($blog mysql_fetch_array($result)){
     
    //I like to use "mysql_fetch_array", but there are many options to this, however, if you decide to use
     // a different method, the below code will have to be altered...
     
    $date  $blog['Date'];
     
    $title $blog['Title'];
     
    $entry $blog['Entries'];
    //$user  = $blog['Username'];
     
    $email $blog['Email'];

     
    //this file is described below, it handles the displaying of the actual information
     // the hard part, querying the database and gathering all the information, is done.
     // If you ever want to only display the first so many entries at one time, there is
     // a clause that you can add to the SQL query above to do so, just add (I believe)
     // the LIMIT clause, and follow it with a number, such as:
     // SQL CODE: [...] LIMIT 10
     // It's easiest just to add it to the end.  Change "10" to whatever number you'd want.
     
    include 'templates/entry.php';
    }

    ?>
    <br><br><br><br>

    <br>
    <------FOOTER------>
    <br><br><br><br><br><br><br>
    <? include 'copyright.html'?>
    </body>

    </html>
    Here is the template file thats gets included in index.php toward the end of the file:

    PHP Code:
    <?php
    include '/home/adamb10/public_html/UltraBlog/Sources/mysqlconnect.php';
    //This file contains the HTML used as a template for each entry so that you can easily
    // change the formatting of your entries, whenever you wish.  If you get fancy, you can
    // create a web-based interface that can access this file and update the informtion
    // contained in it and auto-"magically", all of your entries have a new look.  :)

    //The only things that are not HTML are the PHP variables that are being printed within the template.  If you do not have short-tags turned on in your PHP ini file, you
    // will have to change the <?=$variable to <?php echo $variable; .  Technically, the
    // latter is better, but for looks, and for those who don't understand PHP, the smaller
    // things are, the better.
    ?>
    <table width="80%" cellspacing="1" cellpadding="1" border="0" class="border">
     <tr>
       <th class="titlebg"><?=$title?></th>
       <th class="titlebg" width="145"><?=$date?></td>
     </tr>
     <tr>
       <td class="titlebg" colspan="2"><?=$entry?></td>
     </tr>
    </table><p />
    I've been trying to figure this out for about a month and am anxious to get this fixed.


    Thanks!

    Adam

  2. #2
    SitePoint Addict loadx's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne, VIC, Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <th class="titlebg"><?=$title?></th>
       <th class="titlebg" width="145"><?=$date?></td>
    this should be like

    PHP Code:
    while($blog mysql_fetch_array($result)){

    $date  $blog['Date'];
    $title $blog['Title'];
    $entry $blog['Entries'];
    $user  $blog['Username'];
    $email $blog['Email']; 

    echo 
    '<th class="titlebg">'.$title.'</th>';
    echo 
    '<th class="titlebg" width="145">'.$date.'</td>';

    etc etc


  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Milwaukee Wisconsin
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It still doesn't show.

    Thanks,
    Adam

  4. #4
    SitePoint Addict loadx's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne, VIC, Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you get any errors from the query?

  5. #5
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Milwaukee Wisconsin
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. It just seems if the while statement is getting completly ignored unless I add another = to it which returns the end ammount of things.

  6. #6
    SitePoint Addict loadx's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne, VIC, Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    show me what you changed it to...

    view the source

    you were closing a th with a td... that cant work very well :S

  7. #7
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Milwaukee Wisconsin
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres the while statment with the change:

    PHP Code:
    while($blog == mysql_fetch_array($result)){ 
     
    //I like to use "mysql_fetch_array", but there are many options to this, however, if you decide to use
     // a different method, the below code will have to be altered...
     
    $date  $blog['Date'];
     
    $title $blog['Title'];
     
    $entry $blog['Entries'];
    //$user  = $blog['Username'];
     
    $email $blog['Email'];
     
    //this file is described below, it handles the displaying of the actual information
     // the hard part, querying the database and gathering all the information, is done.
     // If you ever want to only display the first so many entries at one time, there is
     // a clause that you can add to the SQL query above to do so, just add (I believe)
     // the LIMIT clause, and follow it with a number, such as:
     // SQL CODE: [...] LIMIT 10
     // It's easiest just to add it to the end.  Change "10" to whatever number you'd want.
    include './templates/entry.php';
    }

    ?> 
    Here is the template file with the change:

    PHP Code:
    <table width="80%" cellspacing="1" cellpadding="1" border="0" class="border">
     <tr>
     <?
     
    echo '<th class="titlebg">'.$title.'</th>'
    echo 
    '<th class="titlebg" width="145">'.$date.'</td>';
    ?>
     </tr>
     <tr>
       <td class="titlebg" colspan="2"><?=$entry?></td>
     </tr>
    </table><p />
    Thanx,
    Adam

  8. #8
    SEO Addict eli03's Avatar
    Join Date
    Aug 2004
    Location
    Pasig City Cainta, Philippines
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have two $result, try to change that with another varibale

  9. #9
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Milwaukee Wisconsin
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just did and it didn't work. I removed the extra = from the while statement to prevent firefox from crashing.

    Thanks,
    Adam

  10. #10
    SEO Addict eli03's Avatar
    Join Date
    Aug 2004
    Location
    Pasig City Cainta, Philippines
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try to use double quote on this select statement

    $sql = 'SELECT entrys.Id, entrys.Date, entrys.Title, entrys.Entries, Userdata.Email FROM entrys, Userdata WHERE entrys.UserID=Userdata.Id ORDER BY Date DESC';

    should be

    $sql = "SELECT entrys.Id, entrys.Date, entrys.Title, entrys.Entries, Userdata.Email FROM entrys, Userdata WHERE entrys.UserID=Userdata.Id ORDER BY Date DESC";

    I think this will work now

  11. #11
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Milwaukee Wisconsin
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still does not work.

    Thanks,
    Adam


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
  •