Results 1 to 4 of 4

Thread: Bit of very basic php/mysql help needed, please chaps!

  1. #1
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value

    Bit of very basic php/mysql help needed, please chaps!

    Just a quickie, I hope. I'm making a little website for a friends band from Argentina, and have made a quick, basic php script which allows them to post stuff on a news page from a html form. Here's the php script for entering into the database:

    Code:
    <?php 
    
    $title = $_POST["title"]; 
    $text = $_POST["text"];  
    
    $connection = mysql_connect("localhost","username","password") or die ("Couldn't connect to database server."); 
    
    $db = mysql_select_db("dbname" , $connection) or die("Couldn't select database."); 
    
    $sql = "insert into psychotoxic values ('$title', '$text')"; 
    
    
    $sql_result = mysql_query($sql,$connection) or die("Couldn't execute query"); 
    
    mysql_close($connection); 
    
    print "Information Accepted." 
    
    ?>
    This works completely fine, not a problem.

    I have also made a script to extract 5 entries from the database, and place them in a html table:

    Code:
    <?php 
    
    include("logo.htm");
    $connection = mysql_connect("localhost","usernamei","password") or die ("Couldn't connect to database server."); 
    
    $db = mysql_select_db("dbname" , $connection) or die("Couldn't select database."); 
    
    $sql = 'SELECT `title` , `text` ';
    $sql .= 'FROM `psychotoxic` ';
    $sql .= 'WHERE 1 LIMIT 0, 5';
    
    $sql_result = mysql_query($sql,$connection) or die("Couldn't execute query"); 
    echo "<br><br><table border=0 table width=700>";
    
    while ($myrow = mysql_fetch_array($sql_result)) { 
        $title = $myrow["title"]; 
       $text = $myrow["text"]; 
       echo "
     <tr>
        <th>
         <strong>$title</strong></th>
    	<tr><td><h1>
          $text
        </h1></td>
      </tr>
    ";
    } 
    
    echo "</TABLE>"; 
    
    mysql_free_result($sql_result); 
    mysql_close($connection); 
    
    ?>
    This also works great, but I need it to extract the 5 newest entries rather than the 5 entries that were first entered into the database. I also need it to put the newest entry first, then going down the list as the entries get older.

    I apologise for my English, bit tired at the moment If anyone could help me with figure out what I need to do, I'll greatly appreciate any comments/suggestions.

  2. #2
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value
    Figured it, ta for reading anyway

  3. #3
    Furry Shorty's Avatar
    Join Date
    Jul 2003
    Location
    Manchester, UK
    Posts
    1,237
    Thanks
    1
    Thanked
    2 times in 2 posts
    You solved it anyway but you needs an ORDER BY clause in there
    "In a world without walls and fences, who needs Windows and Gates?"

  4. #4
    Kirstie Allsopp Theo's Avatar
    Join Date
    Jul 2003
    Location
    Sunny Bolton
    Posts
    2,777
    Thanks
    17
    Thanked
    23 times in 20 posts
    • Theo's system
      • Motherboard:
      • Asus P5B Wifi deluxe
      • CPU:
      • E6600 @ 3150Mhz
      • Memory:
      • 2x2GB OCZ 6400
      • Storage:
      • 1x80GB Maxtor
      • Graphics card(s):
      • 640MB 8800GT
      • Monitor(s):
      • ASUS M221u
      • Internet:
      • Be Value
    Jup :>

    The band love the website - all it needs now is a little additional content, and to be transferred onto their webspace/url. Much nicer than their current site - www.psychotoxic.com.ar

    It'll probably go live in the next week, or so. I've got to go learn JAVA from scratch for a uni assignment due in on Tuesday, now....

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Quick and easy PHP help needed chaps
    By Kezzer in forum Software
    Replies: 20
    Last Post: 23-02-2004, 07:45 PM
  2. Bit of help needed....
    By Jonlad in forum Apple Mac
    Replies: 3
    Last Post: 23-02-2004, 03:19 PM
  3. Bit of basic PHP help, please chaps?
    By Theo in forum Software
    Replies: 4
    Last Post: 04-12-2003, 02:54 AM
  4. Radeon 8500 linux driver install problems
    By Dorza in forum Software
    Replies: 0
    Last Post: 22-09-2003, 12:00 PM

Posting Permissions

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