Share one page of news publishing with multiple data tables

Source: Internet
Author: User

In order to be simple and 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 ---
<? PH
$ Query = "select * from". $ name. "order by id desc limit 0, 5;
$ Result = mysql_query ($ query, $ dB );
If ($ result ){
While ($ myrow = msyql_fetch_array ($ result )){
?>
<Tr> <TD> <a href = "view_d.php? Recod = <? PHP echo $ myrow [ID];?> & Name = <? PHP echo $ name;?> "> $ Myrow [title] </a> </TD> </tr>
<? PHP
}
}
Else {
Echo "there is no new content yet. ";}
?>

---- Index. php ---
<? PHP
$ Id = mysql_connect ("localhost", "username", "password ");
$ Db = mysql_select_db ("your_db", $ id );
?>
<HTML>
<Body>
<HR size = 0 color = green width = 100%>
<P align = left> <font color = green size = + 3> yourname online </font> </P>
<HR size = 3 color = green width = 100%>
<P align = left> <font size =-1> your current location --> homepage </font> </P>
<HR size = 2 color = green width = 100%>
<Table width = 100 border = 0 cellpadding = 0 cellspacing = 0>
<Tr>
<! -- News -->
<TD width = 50% align = left>
<Table width = 100 border = 0 cellpadding = 0 cellspacing = 0>
<? PHP
$ Name = News;
Include ("index_view.php ");
?>
</Table>
</TD>
<! -- CTM -->
<TD width = 50% align = left>
<Table width = 100 border = 0 cellpadding = 0 cellspacing = 0>
<? PHP
$ Name = CTM;
Include ("index_view.php ");
?>
</Table>
</TD>
</Tr>
</Table>
<HR size = 0 width = 100% color = green>
<P align = center> <font size =-1> copyrignt 1999... </Font> </P>
</Body>
</Html>

---- Index_pub.php ---
<? PHP
$ Id = mysql_connect ("localhost", "username", "password ");
$ Db = mysql_select_db ("your_db", $ id );
?>
<HTML>
<Body>
<Form action = index_view.php method = post>
<P> select a database: <br>
<Select name = db_name size = 1>
<Option value = News> News </option>
<Option value = CTM> CTM </option>
</SELECT> </P>
<P> title: <br>
<Input type = text name = title size = 20> </P>
<P> content: <br>
<Textarea rows = 6 Cols = 10 name = detail> </textarea> </P>
<P> <input type = submit value = submit> </P>
</Form>
<? PHP
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 ";}
?>
</Body>
</Html>

---- 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. "

";
}< br> else {echo "this file has been deleted! ";}< Br>

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.