Share one page of news publishing with multiple data tables

Source: Internet
Author: User
Multiple data tables share one page of news publishing this article to be simple and can describe the main content, some secondary html content is relatively simple.
When the website has multiple content to be displayed on a page, you can use one display and submit on the page.
In this example, there are two data tables (news, ctm) and one home page (index. php );
One submission page (index_pub.php; and one package page (index_view.php)
A child page (view_d.php ).
---- News, ctm ---
Increate table news (id int (80) not null auto_increment, title char (100), detail text, primay key (id ));
Increate table ctm (id int (80) not null auto_increment, title char (100), detail text, primay key (id ));


---- Index_view.php ---
$ Query = "select * from". $ name. "order by id desc limit 0, 5;
$ Result = mysql_query ($ query, $ db );
If ($ result ){
While ($ myrow = msyql_fetch_array ($ result )){
?>
& Name = "> $ Myrow [title]
}
}
Else {
Echo "there is no new content yet. ";}
?>


---- Index. php ---
$ Id = mysql_connect ("localhost", "username", "password ");
$ Db = mysql_select_db ("your_db", $ id );
?>



Yourname Online



Your current location --> homepage















$ Name = news;Include ("index_view.php ");?>






$ Name = ctm;Include ("index_view.php ");?>



Copyrignt 1999...





---- Index_pub.php ---
$ Id = mysql_connect ("localhost", "username", "password ");
$ Db = mysql_select_db ("your_db", $ id );
?>



Switch ($ db_name ){
Case news: $ name = news;
Break;
Case ctm: $ name = ctm;
Break;
}
$ Query = "insert into". $ name. "(title, detail) values ('$ title',' $ detail ');
$ Result = mysql_query ($ query, $ db );
If ($ result) {echo "OK ";}
Else {echo "failed ";}
?>



---- View_d.php ---
$ Id = mysql_connect ("localhost", "username", "password ");
$ Db = mysql_select_db ("your_db", $ id );
?>


If ($ recod ){
$ Query = "select * from". $ name. "where id =". $ recod;
$ Result = mysql_query ($ query, $ db );
$ Title = mysql_result ($ result, 0, title );
$ Detail = mysql_result ($ result, 0, detail );
Echo"

Title: ". $ title ."

";
Echo"

Content: ". $ detail ."

";
}
Else {echo "This file has been deleted! ";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.