Simple online voting system php - get information from home page

WBOY
Release: 2016-07-29 09:07:01
Original
1219 people have browsed it

The method of obtaining information on the home page is the same as the method of obtaining information on the voting page I posted.

<!--主体内容-->
        	<?php
				$sql="select vid,vname,starttime,uid,vintro from vote order by vid DESC";
				$voteItem=mysql_query($sql);
				//循环获取数据库信息
				while($row=mysql_fetch_array($voteItem)){
					$sql2="SELECT username FROM users where uid=".$row[&#39;uid&#39;];
					$uname=mysql_query($sql2);
					$username=mysql_fetch_row($uname);
					//截取前100个字
					$intro=substr($row[&#39;vintro&#39;],0,300)."……";
					//输出
					echo "<div class=&#39;contend_item&#39;>".
							"<table>".
								"<tr><td class=&#39;contend_item_name&#39;><a href=&#39;./select.php?user=".$ouser."&vid=".$row[&#39;vid&#39;]."&#39;>".$row['vname']."</a></td><td>发 布 者:".$username[0]."<br/>发布日期:".$row['starttime']."</td></tr>".
								"<tr><td colspan=&#39;2&#39;>  ".$intro."</td></tr>".
							"</table>".
						"</div>";
				}
        	?>
		<!--主体内容结束-->
Copy after login
1. Submit the sql statement through the mysql_query() method and obtain the query results.

$sql="select vid,vname,starttime,uid,vintro from vote order by vid DESC";
$voteItem=mysql_query($sql);
Copy after login
2. Through looping, use the mysql_fetch_array() method to obtain one record at a time, and obtain the information one by one through the loop. During the loop, the corresponding data is added to the string and displayed. In this way, the function of automatically displaying records on the page is achieved.

(Note: The difference between the mysql_fetch_array() method and the mysql_fetch_row() method. The array method is more like an enhanced version of the row method. The array method not only obtains various information of a record in the form of an array, but also uses the table header. Get various information in the following table to facilitate subsequent calls. The row method does not have the following functions.)

3. Due to the limitation of page width, only part of the voting introduction is displayed. Here, only the first 100 words are intercepted. Display on the page and add "..." at the end

$intro=substr($row['vintro'],0,300)."……";
Copy after login
(In the utf8 format, one Chinese character represents 3 characters, so it should be set to 300 characters.)

The above introduces the simple online voting system PHP - the homepage to obtain information, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!