Current location: Hot Scripts Forums » Programming Languages » PHP » how can i display news on outside page?


how can i display news on outside page?

Reply
  #1 (permalink)  
Old 06-24-05, 11:13 AM
echolike echolike is offline
New Member
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
how can i display news on outside page?

Hi guys,

i am currently write a few lines code to display all news from mysql by date.
db is abc, and there is table called news.

here is the code:

PHP Code:

<?php 

                $username 
"xxx";
                
$password "xxx";
                
$hostname "localhost";    
                
$db mysql_connect($hostname$username$password
                or die(
"Unable to connect to MySQL");
                
$selected mysql_select_db("abc",$db
                or die(
"Could not select abc");
                
 
$result mysql_query('SELECT * FROM news' 'ORDER BY date DESC');

                
$news = array();
                while (
$result $db->row_array()) {
                
$news[] = $result;
                }
                 
?>
but this code seems doesn't work at all.

i need help to show news on outside pages like anywhere in html or php pages.

Thanks guys!!!

sean
Reply With Quote
  #2 (permalink)  
Old 06-24-05, 12:15 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
what are you selecting from news??

SELECT * FROM news ORDER BY date DESC

you should have:

SELECT title, news, author, date FROM news ORDER BY date DESC

then the whole thing would look like:

PHP Code:

<?php

//Connect
$username "xxx"
$password "xxx"
$hostname "localhost";     
mysql_connect($hostname$username$password) or die("Unable to connect to MySQL"); 
mysql_select_db("abc",$db) or die("Could not select abc");

//Query
$query mysql_query("SELECT title, news, author, date FROM news ORDER BY date DESC");

//Repeat
while($r mysql_fetch_array($query)) {
$title $r['title'];
$news $r['news'];
$author $r['author'];
$date $r['date'];

//Echo news
echo "Title: <b>$title</b>
<br><br>
$news
<br><br>
<i>Posted by 
$author on $date.</i>";

}

//Close database
mysql_close();
?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #3 (permalink)  
Old 06-24-05, 02:15 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
One problem in your original code may have been this query:
Code:
mysql_query('SELECT * FROM news' . 'ORDER BY date DESC');
When you remove the concantonation, the query would read:
Code:
mysql_query('SELECT * FROM newsORDER BY date DESC');
You'll see there's no space between 'news' and 'ORDER'.
Reply With Quote
  #4 (permalink)  
Old 06-24-05, 02:20 PM
echolike echolike is offline
New Member
 
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi guys,

Thank you so much, that help me a lot.



sean
Reply With Quote
  #5 (permalink)  
Old 06-24-05, 11:21 PM
jordie jordie is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 179
Thanks: 0
Thanked 0 Times in 0 Posts
FiRE you can use * to select all the columns. Much simplier then typing them all out
__________________
Jordie Bodlay
php, mysql, postgres
css, xhtml
graphics, design
email me: jb2386@hotmail.com for any programming needs.
Reply With Quote
  #6 (permalink)  
Old 06-25-05, 12:33 AM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
But that can also slow down queries and call unnecessary info, so be careful when using a wildcard.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help! Display Records page by page peter_toronto PHP 5 02-20-08 09:12 AM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
page browsing problem mivec PHP 3 04-17-04 03:43 AM
page load time display epic1231 PHP 2 03-10-04 11:33 PM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 06:51 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.