Random extraction of data and jquery supplemental effects (menu, mobile)

Source: Internet
Author: User

One, the random extraction of data

Have seen that kind of test question from a lot of questions randomly take a few of the papers, now you have to do such an example: randomly extract a few data from the database to display (for example: 100 randomly selected 50)

Random selection is to have submitted data, so must have a visual interface and background processing page

(1) Submission interface

A. Use form submission (make a form, this is the page layout of the program, in which there is no doubt that the from form will be used) as follows:

<form action= "nt.php" method= "POST" >      <div class= "Net_title" > select title: <input id= "Net_xuan" type= "text" Style= "width:50px" name= "Net_xuan"/></div>        <div class= "Net_title" ><input type= "Submit" value = "Quiz"/></div></form>

B. Submitted processing page

<?phpinclude (".. /.. /js/dbda.class.php ");   Encapsulated Database Class $db = new Dbda (); $nx = $_post["Net_xuan"];   Number of selected questions       //Query code value and Execute $SQLN = "Select title from subject where Code= '"; Echo $db->strquery ($SQLN);// Select whether the question is empty if ($nx = = "" && $nd = = "" && $ns = = "" && $nm = = "") {return false;   Returns false}else{$sql = "Select title from subject where code= ' 1101 '";  The selection code is 1101 of the topic $attrx =  $db->query ($sql);  Execute statement foreach ($attrx as $VXT)   //loop display {echo <p> A, {$vxt [0]}</p> ";//Big title} $SQLX =" Select Title,xiang From subject where fcode= ' 1101 ' ORDER by rand (code) limit 0, $nx ";  Randomly extracting the topic according to the Code name (order by rand (code) limit 0, $nx) $attr =  $db->query ($SQLX);//Execute statement foreach ($attr as $v)  //loop Display { for ($i =1; $i <count ($v), $i + +) {echo "<div> $i {$v [0]}</div><br><div>{$v [1]}</div> <br> ";//display of the topic}}}

The main thing here: how to write a random question, in fact, sort the number of extracts, using rand () random number (order by rand (code) limit 0,3)

In this case, the random number is drawn out ~ ~ ~ If you want to not repeat the random words, you can add non-repeating distinct in the query statement

Second, fragmented knowledge points

(1) JQ menu

Effect: the mouse movement on the color difference, click on the display, the mouse out of the menu to show only the selected effect, the other is not, the mouse moved on the display of the color moved

A. Display style not much to say, how the layout will be, directly look at the code and effects, as follows:

<ul>    <li class= "Xiang" > Project one </li><!--all add a name followed by a name--    <li class= "Xiang" > Project two </li>    <li class= "Xiang" > Project three </li>    <li class= "Xiang" > Project four </li></ul >

B. The JQ logic is written as follows:

Mouse click to select the $ (". Xiang"). The Click (function () {//all element background color becomes the original $ (". Xiang"). Removeattr ("XZ"); $ (". Xiang"). CSS (" Background-image "," url (.. /img/lift_li_bj_02.gif);//find who clicked on $ (this). attr ("XZ", "1"); $ (this). CSS ("background-image", "url (.. /img/lift_li_02_02.gif) ");}) Move the mouse over $ (". Xiang"). MouseMove (function () {//all element background color becomes the original $ (". Xiang"). CSS ("background-image", "url (.. /img/lift_li_bj_02.gif);//find who clicked on the $ (this). CSS ("background-image", "url (. /img/lift_li_02_02.gif), $ ("[xz= ' 1 ']"). CSS ("background-image", "url (.. /img/lift_li_02_02.gif) ");}) The mouse moves out of $ (". Xiang"). Mouseout (function () {//all element background color becomes the original $ (". Xiang"). CSS ("background-image", "url (.. /img/lift_li_bj_02.gif);//find who clicked on $ ("[xz= ' 1 ']"). CSS ("background-image", "url (.. /img/lift_li_02_02.gif) ");})

  

(2) JQ mouse Click box, the box moves with the mouse

A. The style of the display box, here is a normal box, as follows:

(1) DIV display

<div class= "AA" >     <p> mouse down can drag me to move oh ~</p>     <p> mouse release I won't move, oh ~</p></div>

(2) style (style effect is not much to say, are written simple style) as follows:

<style>    . aa{height:100px;  /* wide, high */width:300px; Position:absolute;  /* Position */border:6px solid #90F;  /* Border */text-align:center;   /* Inside Content location */vertical-align:middle; line-height:25px;       } </style>

As follows:

B.JQ Mobile Effect Logic writing

Locate the box name and add the event $ (". AA"). MouseDown (function (e) {  //mouse down $ (document). Bind ("MouseMove", function (e) {  //bind () Event Hangs: Binding event (event name, execution code) $ (". AA"). CSS ("left", E.pagex). CSS ("top", E.pagey)  //pagex and Pagey can get the coordinate position of mouse movement}) $ (". AA"). MouseUp (function () {  //mouse release $ (document). Unbind ("MouseMove")  //Remove Event: Unbind (event name)})

  

The overall effect of this logic is as follows:

A. The effect of the mouse without dragging:

B. The effect of dragging after the mouse is pressed:

Pagex and Pagey but get the values of the horizontal and vertical axes of the mouse

<p> mouse pointer at: <span></span></p> <!--This is a display of the mouse horizontal value--

$ (document). Ready (function () {  $ (document). MouseMove (function (e) {//mouse move    $ ("span"). Text ("X:" + E.pagex + ", Y : "+ e.pagey); Add content to span, which is where the mouse moves to show values in span  });

At any time to add knowledge points ~ ~

Learning and sharing is not a conflict.

Random extraction of data and jquery supplemental effects (menu, mobile)

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.