Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: [php/mysql]

  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question [php/mysql]

    can someone please tell me whats wrong here

    PHP Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost""user""password") or die(mysql_error());
    mysql_select_db("cms") or die(mysql_error());

    // Get all the data from the "example" table
    $result mysql_query("SELECT * FROM news ORDER BY id"
    or die(
    mysql_error());  

    // keeps getting the next row until there are no more to get
    while($row mysql_fetch_array$result )) {
        
    // Print out the contents of each row into a table

    ?>





    <div id="post_bg">
    <div id="post_txt">
    <img src="images/admin_icon.png" width="90px" height="90px" id="post_img">

    <a href="#"><?php
        
    echo $row['title'];

    ?></a><br />
    <p class="post_text"><font size="-1" face="Times New Roman, Times, serif"><?php
        
    echo $row['content'];

    ?> <br /><br /></p></font>
    <label class="post_author"><i>Posted by <a href="#"><?php
        
    echo $row['author'];

    ?></a> <?php
        
    echo $row['date'];

    ?> <a href="#"><?php
        
    echo $row['comments'];

    ?></a></label></i></font>

    </div>
    </div>

    i keep getting syntax error when adding more than 1 echo, i tried only the ['title'] one and it worked but when i started to add content,author,date and comments i get the error.
    also the design gets ugly if i add more than 1 news to the database.
    Last edited by epxine; 11-16-2011 at 11:28 PM.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    It probably is because you close the while loop right after you echo the title. Remove the closing brackets } you have added to every one of them and only close the while loop after the last one.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,466
    Thanks
    71
    Thanked 104 Times in 103 Posts
    The problem is you're using a half dozen closing brackets. Use this code.

    PHP Code:
    <a href="#"><?php
        
    echo $row['title'];

    ?></a><br />
    <p class="post_text"><font size="-1" face="Times New Roman, Times, serif"><?php
        
    echo $row['content'];

    ?> <br /><br /></p></font>
    <label class="post_author"><i>Posted by <a href="#"><?php
        
    echo $row['author'];

    ?></a> <?php
        
    echo $row['date'];

    ?> <a href="#"><?php
        
    echo $row['comments'];
    }
    Spookster beat me to it by seconds!
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by myfayt View Post
    The problem is you're using a half dozen closing brackets. Use this code.

    PHP Code:
    <a href="#"><?php
        
    echo $row['title'];

    ?></a><br />
    <p class="post_text"><font size="-1" face="Times New Roman, Times, serif"><?php
        
    echo $row['content'];

    ?> <br /><br /></p></font>
    <label class="post_author"><i>Posted by <a href="#"><?php
        
    echo $row['author'];

    ?></a> <?php
        
    echo $row['date'];

    ?> <a href="#"><?php
        
    echo $row['comments'];
    }
    Spookster beat me to it by seconds!
    Thanks both of you!
    Last edited by epxine; 11-17-2011 at 02:06 AM.

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts
    how i do to make them only show max 8 topics in that list? so they dont go under the box when theres too many?

  • #6
    New Coder
    Join Date
    May 2009
    Posts
    17
    Thanks
    5
    Thanked 1 Time in 1 Post
    Quote Originally Posted by epxine View Post
    how i do to make them only show max 8 topics in that list? so they dont go under the box when theres too many?
    Code:
    $result = mysql_query("SELECT * FROM news ORDER BY id LIMIT 8")

  • Users who have thanked s2ooz for this post:

    epxine (11-17-2011)

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by s2ooz View Post
    Code:
    $result = mysql_query("SELECT * FROM news ORDER BY id LIMIT 8")
    Awesome thanks!

    also do you know how to make the latest topics in the top? instead of having the first topic_id 1 at the top all time? so it dosn't stays the same if you knw what i mean

  • #8
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,466
    Thanks
    71
    Thanked 104 Times in 103 Posts
    PHP Code:
    $result mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 8"
    or

    PHP Code:
    $result mysql_query("SELECT * FROM news ORDER BY topic_id DESC LIMIT 8"
    Been a sign maker for 7 years. My business:
    American Made Signs

  • Users who have thanked myfayt for this post:

    epxine (11-17-2011)

  • #9
    New Coder
    Join Date
    Nov 2011
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts
    <3 you guys! ty alot


  •  

    Posting Permissions

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