Home > Article > Backend Development > Simple online voting system php - get information from home page
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['uid']; $uname=mysql_query($sql2); $username=mysql_fetch_row($uname); //截取前100个字 $intro=substr($row['vintro'],0,300)."……"; //输出 echo "<div class='contend_item'>". "<table>". "<tr><td class='contend_item_name'><a href='./select.php?user=".$ouser."&vid=".$row['vid']."'>".$row['vname']."</a></td><td>发 布 者:".$username[0]."<br/>发布日期:".$row['starttime']."</td></tr>". "<tr><td colspan='2'> ".$intro."</td></tr>". "</table>". "</div>"; } ?> <!--主体内容结束-->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);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)."……";(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.