问:
how to avoid duplication users in my db with php
How are you all,

hope every one here is OK,

now I have a form that the admin can create users and he can delete users as will let me display the code first

this is my code

```<code>> > <?php error_reporting(E_ALL);
>
> session_start();
>   if(!isset($_SESSION['login']) ||
> $_SESSION['login']!='1' )         {
>       header("Location:loginpage.php");
>       } ?>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD
> XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html
> xmlns="http://www.w3.org/1999/xhtml">
> <head> <meta http-equiv="Content-Type"
> content="text/html; charset=utf-8" />
> <title>My Control panel</title> <link
> href="../css_style.css"
> rel="stylesheet" type="text/css" />
> </head>
>
>
>
> <body> <div id="werpper"> <div
> id="content">
>
> <div id="header">My control -
> Panel</div> <div id="body_cntent">
> <div id="left_side">   <p>Home and
> instructions</p>   <p><a
> href="../control_panel.php">main
> directory</a></p>   <p><a
> href="add_event.php">Add new
> event</a></p>   <p><a
> href="../editoccasion.php">Control
> Occasion's</a></p>   <p><a
> href="add_photos_and_occasion.php">Add
> Photos_occasion</a></p>   <p><a
> href="../signout.php">Sign out</a></p>
> </div> <div id="right_side">
>
> <h2>Add new user</h2>
>
> <form action="" method="post">
>
> <table width="600" border="0"
> cellpadding="5" cellspacing="0">
> <tr>
>     <td width="78">User name</td>
>     <td width="2"> </td>
>     <td width="149"><input type="text" name="uname" value="" /></td>
>     <td width="332" rowspan="5" align="left" valign="top"><p
> class="red">For Administration use
> only.</p>
>       <p>You can add or delete users from <a
> href="edit_users.php">here</a><br />
>         You can't edit any user if you like to change any user account you
> can delete the user and create it
> again with the new
> information.</p></td>   </tr>   <tr>
>     <td>Password</td>
>     <td> </td>
>     <td><input type="text" name="pass" value="" /></td>
>     </tr>   <tr>
>     <td> </td>
>     <td> </td>
>     <td><input type="submit" name="submit" value="Add user" /></td>
>     </tr>   <tr>
>     <td> </td>
>     <td> </td>
>     <td> </td>
>     </tr>   <tr>
>     <td> </td>
>     <td> </td>
>     <td align="right"> </td>
>     </tr> </table> </form>
>
> </div> </div>
>
> <div id="footer"></div> </div> </div>
>
> <?php
>       if (isset($_POST['submit'])) {
>               include_once "../config/config.php";
>               $uname = $_POST['uname'];       $pass =$_POST['pass'];
>               $check = "select * from users where id = {$uname}";         $result_check
> = $db->query($check)or die($db->error);
>
>               while ($row = $result_check -> fetch_object()) {
>                       if(num_rows == 1){
>
>               echo "error";
>
>               }else{
>               $add_user = "insert into users (id, uname, pass) values ('',
> '$uname', '$pass')";
>               $result = $db -> query($add_user) or die ("$db->error");
>               if ($result) {
>                       echo "user added successfuly";
>                       }else{
>
>               echo "There was an error please try again later";
>
>               }           }       }   } ?>
>
> </body> </html>
</code>```

all I need here to know is how to solve the problem of this code

```<code>$check = "select * from users where id = {$uname}";
        $result_check = $db->query($check)or die($db->error);

        while ($row = $result_check -> fetch_object()) {

            if(num_rows == 1){

                echo "error";

                }
</code>```

how can I avoid duplication users in my db

答:
OK just found my answer on stack overflow I love this site and all the people there

this is the answer

```<code>$check = $db->query("SELECT 1 FROM users WHERE uname='$uname'");
            if (mysqli_num_rows($check) > 0) {
                die('username already taken');
</code>```

it is very simple and also it uses the same concept of the count() and if some one know something about the count please write it to us

Thanks all, and regards,
Yousef Altaf

Body:
How are you all,

hope every one here is OK,

now I have a form that the admin can create users and he can delete users as will let me display the code first

this is my code

> > <?php error_reporting(E_ALL);
>
> session_start();
>   if(!isset($_SESSION['login']) ||
> $_SESSION['login']!='1' )         {
>       header("Location:loginpage.php");
>       } ?>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD
> XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>  xmlns="http://www.w3.org/1999/xhtml">
>  <meta http-equiv="Content-Type"
> content="text/html; charset=utf-8" />
> <title>My Control panel</title> <link
> href="../css_style.css"
> rel="stylesheet" type="text/css" />
>
>
>
>
>

 id="content">
>
>
My control -
> Panel

>

Home and
> instructions

 href="../control_panel.php">main
> directory

 href="add_event.php">Add new
> event

 href="../editoccasion.php">Control
> Occasion's

 href="add_photos_and_occasion.php">Add
> Photos_occasion

 href="../signout.php">Sign out

>

>
>
Add new user

>
> <form action="" method="post">
>
>
 cellpadding="5" cellspacing="0">
>

>     User name
>
>     <input type="text" name="uname" value="" />
>
 class="red">For Administration use
> only.

>
You can add or delete users from  href="edit_users.php">here

>         You can't edit any user if you like to change any user account you
> can delete the user and create it
> again with the new
> information.

>     Password
>
>     <input type="text" name="pass" value="" />
>

>
>
>     <input type="submit" name="submit" value="Add user" />
>

>
>
>
>

>
>
>
>

 </form>
>
>

>
>

>
> <?php
>       if (isset($_POST['submit'])) {
>               include_once "../config/config.php";
>               $uname = $_POST['uname'];       $pass =$_POST['pass'];
>               $check = "select * from users where id = {$uname}";         $result_check
> = $db->query($check)or die($db->error);
>
>               while ($row = $result_check -> fetch_object()) {
>                       if(num_rows == 1){
>
>               echo "error";
>
>               }else{
>               $add_user = "insert into users (id, uname, pass) values ('',
> '$uname', '$pass')";
>               $result = $db -> query($add_user) or die ("$db->error");
>               if ($result) {
>                       echo "user added successfuly";
>                       }else{
>
>               echo "There was an error please try again later";
>
>               }           }       }   } ?>
>
>

all I need here to know is how to solve the problem of this code

$check = "select * from users where id = {$uname}";
        $result_check = $db->query($check)or die($db->error);

        while ($row = $result_check -> fetch_object()) {

            if(num_rows == 1){

                echo "error";

                }

how can I avoid duplication users in my db

Body:
OK just found my answer on stack overflow I love this site and all the people there

this is the answer

$check = $db->query("SELECT 1 FROM users WHERE uname='$uname'");
            if (mysqli_num_rows($check) > 0) {
                die('username already taken');

it is very simple and also it uses the same concept of the count() and if some one know something about the count please write it to us

Thanks all, and regards,
Yousef Altaf


来源: stackexchange

问:
javascript setInterval() Slider
i'm not that good in JavaScript if you can halp me..i have a slide, what i have to do is to add a bottom to either make it autoplay or stop it. when i put just an Alert inside the function it works but when i put the interval code it won't. here is my codepen link

here is my slide code:

```<code><div class="Dash_map_wrapSlider" id="Dash_map_wrapSlider">
            <div style="border: 1px solid red;width: 100%;">
                <input id="Dash_map_sumSlideSite" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>
                <div class="Dash_map_sumSlide slide_Site " style="float: left;width: 50%;border: 2px solid yellow;">
                    <div class="clsDashMap_sumSlideTitle">SITE</div>
                    <div class="clsDashMap_sumSlideSiteContentSummary">
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
                            <div class="green led">OK</div>
                            <div class="red led">KO</div>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">AlarmesSite</div>
                            <canvas id="pieChartAlm" ></canvas>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">TicketsSite</div>
                            <canvas id="pieChartTkt" ></canvas>
                        </div>
                    </div>
                    <div class="clsDashMap_sumSlideContent">put here content</div>
                </div>

                <div class="Dash_map_sumSlide slide_Alarme" style="float: left;width: 50%; border: 2px solid green;">
                    <div class="clsDashMap_sumSlideTitle" style="left:0;">ALARME</div>
                    <div class="clsDashMap_sumSlideSiteContentSummary">
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
                            <div class="green led">OK</div>
                            <div class="red led">KO</div>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">ALARME1Alm</div>
                            <canvas id="pieChartAlm" ></canvas>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Tickets1Alm</div>
                            <canvas id="pieChartTkt" ></canvas>
                        </div>
                    </div>
                    <div class="clsDashMap_sumSlideContent">put here content</div>
                </div>
            </div>

            <div style="border: 1px solid red;">
                <input id="Dash_map_sumSlideAlarme" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>
                <div class="Dash_map_sumSlide slide_Site " style="width: 50%;border: 2px solid black;">
                    <div class="clsDashMap_sumSlideTitle">TECHNICIEN</div>
                    <div class="clsDashMap_sumSlideSiteContentSummary">
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
                            <div class="green led">OK</div>
                            <div class="red led">KO</div>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Alarmes2Tech</div>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Tickets2Tech</div>
                        </div>
                    </div>
                    <div class="clsDashMap_sumSlideContent">put here content</div>
                </div>
                    <div class="Dash_map_sumSlide slide_Alarme" style="width: 50%;border: 2px solid darkturquoise;">
                    <div class="clsDashMap_sumSlideTitle" style="position: initial;">ACTION</div>
                    <div class="clsDashMap_sumSlideSiteContentSummary">
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
                            <div class="green led">OK</div>
                            <div class="red led">KO</div>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">alarme3Act</div>
                        </div>
                        <div class="clsDashMap_sumSlideContentBox">
                            <div class="clsDashMap_sumSlideContentBoxTitle">Tickets3Act</div>
                        </div>
                    </div>
                    <div class="clsDashMap_sumSlideContent">put here content</div>
                </div>
            </div>
</code>```

```<code>            <div class="Dash_map_wrapSliderchoise">
                <label for="Dash_map_sumSlideSite">Site / Alarme</label>
                <label for="Dash_map_sumSlideAlarme">Technicien / Action</label>
      <span id="autoplay" style="color:#fff;">Autoplay</span>
            </div>
</code>```

My JS code :

```<code>function playSlide() {
        console.log('heeey');
        var elementSlide = document.getElementById('autoplay');
        elementSlide.onclick = function(){
            //alert('hey beauty !');
            setInterval(function(){
                $('#autoplay');
            }, 3000);
        };
    }
</code>```

Thank you !

答:
Try modifying your playSlide method like this. This will iterate through the radio buttons and check the next every 3 seconds.

var nextSlide = 0;
var slideTimer = null;
function playSlide() {
    var elementSlide = document.getElementById('autoplay');

    elementSlide.onclick = function() {
        var slides = document.querySelectorAll('#Dash_map_wrapSlider input[id^="Dash"]');

        if (!slideTimer) {
            elementSlide.innerHTML = "Stop";
            slideTimer = setInterval(function() {
                if (slides.length <= nextSlide)
                    nextSlide = 0;

                console.log('showing slide ' + nextSlide);
                slides.forEach(function (slide, index) {
                    slide.checked = index === nextSlide;
                });

                nextSlide++;
            }, 3000);
        } else {
            elementSlide.innerHTML = "Start";
            clearInterval(slideTimer);
            slideTimer = null;
        }
    };
}

playSlide();```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.Dash_map_wrapSlider {
 position: absolute;
 overflow: hidden;
 height: 100%;
 width: calc(100% - 3rem);
 bottom: calc(-80% + 10rem);
 left: 3rem;
 background: #fff;
 border: 1px solid;
 transition: 0.5s;
 z-index: 1;
}
.Dash_map_wrapSlider:hover{
 bottom: 0rem;
 transition: 0.5s;
}
.Dash_map_wrapSliderchoise {
 background: #3E474F;
 box-shadow: 0 .5em 1em #111;
 position: absolute;
 left: 0;
 bottom: 0;
 z-index: 900;
 width: 100%;
 height: 2rem;
 line-height: 2rem;
 text-align: center;
 vertical-align: middle;
}
.Dash_map_sumSlide {
 height: 100%;
 width: 100%;
 position: absolute;
 top: 0;
 left: 100%;
 z-index: 10;
 background-color: #fff;
 transition: left 0s .75s;
}
.clsDashMap_sumSlideInput {
 display: none;
 height: 11rem;
}
.clsDashMap_sumSlideTitle {
 position : absolute;
 top:0;
 width: 100%;
 height: 2rem;
 left: inherit;
 color: #fff;
 background-color: #73b9ff;
 text-align: center;
 font-weight: bold;
 font-size: 1.20rem;
}
.clsDashMap_sumSlideContentBoxTitle {
 /*padding: 10%;*/
 font-weight: bold;
 color: #666;
}
.clsDashMap_sumSlideSiteContentSummary {
 position : absolute;
 top: 2rem;
 width: 100%;
 height: 16rem;
 color: #000000;
 background-color: aliceblue;
 text-align: center;
}
.clsDashMap_sumSlideContent {
 position: absolute;
 top: 20rem;
 margin: auto;
 width: 100%;
 color: #000000;
 /* text-align: center; */
}
[id^="Dash"]:checked + .Dash_map_sumSlide {
 left: 0;
 z-index: 100;
 transition: left .65s ease-out;
}
[id^="Dash"]:checked + .Dash_map_sumSlide + .Dash_map_sumSlide { left: 50%; transition-delay: 0.25s; }

.Dash_map_wrapSliderchoise label {
 color: #fff;
 cursor: pointer;
 display: inline-block;
 line-height: 2rem;
 font-size: 0.75rem;
 font-weight: bold;
 padding: 0 1em;

}
/*Style leds*/
.clsDashMap_sumSlideContentBox {
 margin: auto;
 float: left;
    padding: 10px;
    text-align: center;
}
/* .clsDashMap_sumSlideContentBox1Title { */
     /* position: absolute; */
    /* top: -1rem; */
    /* left: 0.3rem; */
/* } */
.led {
 border-radius: 5rem;
 width: 2rem;
 height: 2rem;
 line-height: 2rem;
}
.green {
     background-color: #36d900;
}
.red {
     background-color: #E74C3C;
}
#pieChartAlm, #pieChartTkt {
 margin: auto;
 width: 86%;
}</code>```

     <input id="Dash_map_sumSlideSite" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>

SITE

Etat

OK

KO

AlarmesSite

        <canvas id="pieChartAlm" ></canvas>

TicketsSite

        <canvas id="pieChartTkt" ></canvas>

put here content

ALARME

Etat

OK

KO

ALARME1Alm

        <canvas id="pieChartAlm" ></canvas>

Tickets1Alm

        <canvas id="pieChartTkt" ></canvas>

put here content

     <input id="Dash_map_sumSlideAlarme" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>

TECHNICIEN

Etat

OK

KO

Alarmes2Tech

Tickets2Tech

put here content

ACTION

Etat

OK

KO

alarme3Act

Tickets3Act

put here content

     Site / Alarme
     Technicien / Action
          Start

```

ContentLicense: CC BY-SA 3.0

Title: javascript setInterval() Slider

Body:
i'm not that good in JavaScript if you can halp me..i have a slide, what i have to do is to add a bottom to either make it autoplay or stop it. when i put just an Alert inside the function it works but when i put the interval code it won't. here is my codepen link

here is my slide code:

                <input id="Dash_map_sumSlideSite" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>

SITE

Etat

OK

KO

AlarmesSite

                            <canvas id="pieChartAlm" ></canvas>

TicketsSite

                            <canvas id="pieChartTkt" ></canvas>

put here content

ALARME

Etat

OK

KO

ALARME1Alm

                            <canvas id="pieChartAlm" ></canvas>

Tickets1Alm

                            <canvas id="pieChartTkt" ></canvas>

put here content

                <input id="Dash_map_sumSlideAlarme" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>

TECHNICIEN

Etat

OK

KO

Alarmes2Tech

Tickets2Tech

put here content

ACTION

Etat

OK

KO

alarme3Act

Tickets3Act

put here content

                Site / Alarme
                Technicien / Action
      Autoplay

My JS code :

function playSlide() {
        console.log('heeey');
        var elementSlide = document.getElementById('autoplay');
        elementSlide.onclick = function(){
            //alert('hey beauty !');
            setInterval(function(){
                $('#autoplay');
            }, 3000);
        };
    }

Thank you !

Body:
Try modifying your playSlide method like this. This will iterate through the radio buttons and check the next every 3 seconds.

var nextSlide = 0;
var slideTimer = null;
function playSlide() {
    var elementSlide = document.getElementById('autoplay');

    elementSlide.onclick = function() {
        var slides = document.querySelectorAll('#Dash_map_wrapSlider input[id^="Dash"]');

        if (!slideTimer) {
            elementSlide.innerHTML = "Stop";
            slideTimer = setInterval(function() {
                if (slides.length <= nextSlide)
                    nextSlide = 0;

                console.log('showing slide ' + nextSlide);
                slides.forEach(function (slide, index) {
                    slide.checked = index === nextSlide;
                });

                nextSlide++;
            }, 3000);
        } else {
            elementSlide.innerHTML = "Start";
            clearInterval(slideTimer);
            slideTimer = null;
        }
    };
}

playSlide();

.Dash_map_wrapSlider {
 position: absolute;
 overflow: hidden;
 height: 100%;
 width: calc(100% - 3rem);
 bottom: calc(-80% + 10rem);
 left: 3rem;
 background: #fff;
 border: 1px solid;
 transition: 0.5s;
 z-index: 1;
}
.Dash_map_wrapSlider:hover{
 bottom: 0rem;
 transition: 0.5s;
}
.Dash_map_wrapSliderchoise {
 background: #3E474F;
 box-shadow: 0 .5em 1em #111;
 position: absolute;
 left: 0;
 bottom: 0;
 z-index: 900;
 width: 100%;
 height: 2rem;
 line-height: 2rem;
 text-align: center;
 vertical-align: middle;
}
.Dash_map_sumSlide {
 height: 100%;
 width: 100%;
 position: absolute;
 top: 0;
 left: 100%;
 z-index: 10;
 background-color: #fff;
 transition: left 0s .75s;
}
.clsDashMap_sumSlideInput {
 display: none;
 height: 11rem;
}
.clsDashMap_sumSlideTitle {
 position : absolute;
 top:0;
 width: 100%;
 height: 2rem;
 left: inherit;
 color: #fff;
 background-color: #73b9ff;
 text-align: center;
 font-weight: bold;
 font-size: 1.20rem;
}
.clsDashMap_sumSlideContentBoxTitle {
 /*padding: 10%;*/
 font-weight: bold;
 color: #666;
}
.clsDashMap_sumSlideSiteContentSummary {
 position : absolute;
 top: 2rem;
 width: 100%;
 height: 16rem;
 color: #000000;
 background-color: aliceblue;
 text-align: center;
}
.clsDashMap_sumSlideContent {
 position: absolute;
 top: 20rem;
 margin: auto;
 width: 100%;
 color: #000000;
 /* text-align: center; */
}
[id^="Dash"]:checked + .Dash_map_sumSlide {
 left: 0;
 z-index: 100;
 transition: left .65s ease-out;
}
[id^="Dash"]:checked + .Dash_map_sumSlide + .Dash_map_sumSlide { left: 50%; transition-delay: 0.25s; }

.Dash_map_wrapSliderchoise label {
 color: #fff;
 cursor: pointer;
 display: inline-block;
 line-height: 2rem;
 font-size: 0.75rem;
 font-weight: bold;
 padding: 0 1em;

}
/*Style leds*/
.clsDashMap_sumSlideContentBox {
 margin: auto;
 float: left;
    padding: 10px;
    text-align: center;
}
/* .clsDashMap_sumSlideContentBox1Title { */
     /* position: absolute; */
    /* top: -1rem; */
    /* left: 0.3rem; */
/* } */
.led {
 border-radius: 5rem;
 width: 2rem;
 height: 2rem;
 line-height: 2rem;
}
.green {
     background-color: #36d900;
}
.red {
     background-color: #E74C3C;
}
#pieChartAlm, #pieChartTkt {
 margin: auto;
 width: 86%;
}

<div class="Dash_map_wrapSlider" id="Dash_map_wrapSlider">

    <div style="border: 1px solid red;width: 100%;">
     <input id="Dash_map_sumSlideSite" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>
     <div class="Dash_map_sumSlide slide_Site " style="float: left;width: 50%;border: 2px solid yellow;">
      <div class="clsDashMap_sumSlideTitle">SITE</div>
      <div class="clsDashMap_sumSlideSiteContentSummary">
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
        <div class="green led">OK</div>
        <div class="red led">KO</div>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">AlarmesSite</div>
        <canvas id="pieChartAlm" ></canvas>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">TicketsSite</div>
        <canvas id="pieChartTkt" ></canvas>
       </div>
      </div>
      <div class="clsDashMap_sumSlideContent">put here content</div>
     </div>

     <div class="Dash_map_sumSlide slide_Alarme" style="float: left;width: 50%; border: 2px solid green;">
      <div class="clsDashMap_sumSlideTitle" style="left:0;">ALARME</div>
      <div class="clsDashMap_sumSlideSiteContentSummary">
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
        <div class="green led">OK</div>
        <div class="red led">KO</div>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">ALARME1Alm</div>
        <canvas id="pieChartAlm" ></canvas>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Tickets1Alm</div>
        <canvas id="pieChartTkt" ></canvas>
       </div>
      </div>
      <div class="clsDashMap_sumSlideContent">put here content</div>
     </div>
    </div>

    <div style="border: 1px solid red;">
     <input id="Dash_map_sumSlideAlarme" class="clsDashMap_sumSlideInput" type="radio" name="slides" checked>
     <div class="Dash_map_sumSlide slide_Site " style="width: 50%;border: 2px solid black;">
      <div class="clsDashMap_sumSlideTitle">TECHNICIEN</div>
      <div class="clsDashMap_sumSlideSiteContentSummary">
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
        <div class="green led">OK</div>
        <div class="red led">KO</div>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Alarmes2Tech</div>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Tickets2Tech</div>
       </div>
      </div>
      <div class="clsDashMap_sumSlideContent">put here content</div>
     </div>
      <div class="Dash_map_sumSlide slide_Alarme" style="width: 50%;border: 2px solid darkturquoise;">
      <div class="clsDashMap_sumSlideTitle" style="position: initial;">ACTION</div>
      <div class="clsDashMap_sumSlideSiteContentSummary">
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Etat</div>
        <div class="green led">OK</div>
        <div class="red led">KO</div>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">alarme3Act</div>
       </div>
       <div class="clsDashMap_sumSlideContentBox">
        <div class="clsDashMap_sumSlideContentBoxTitle">Tickets3Act</div>
       </div>
      </div>
      <div class="clsDashMap_sumSlideContent">put here content</div>
     </div>
    </div>

  </div>

    <div class="Dash_map_wrapSliderchoise">
     <label for="Dash_map_sumSlideSite">Site / Alarme</label>
     <label for="Dash_map_sumSlideAlarme">Technicien / Action</label>
          <span id="autoplay" style="color:#fff;">Start</span>
    </div>


问:
Data to remain after hitting Insert Button
In this form when you click on a record from the table that data appears on the form in left. When I click on the Insert button, data gets stored in the database and disappears from the form like there's no record. Is there any way to make the records stay even after I hit the Insert button.

this is my php code for the insertion.

```<code><?php

    if(isset($_POST['submit'])){

    $ID = $_POST['ID'];
    $Name = $_POST['Name'];
    $Location = $_POST['Location'];
    $Date = $_POST['Date'];
    $Category = $_POST['Category'];
    $LabourSupplier = $_POST['LabourSupplier'];
    $BasicSalary = $_POST['BasicSalary'];
    $Allowance1 = $_POST['Allowance1'];
    $InTime = $_POST['InTime'];
    $OutTime = $_POST['OutTime'];
    $Day = $_POST['Day'];
    $DayRate = $_POST['DayRate'];
    $Salary = $_POST['Salary'];
    $OtHours = $_POST['OtHours'];
    $OTrate = $_POST['OTrate'];
    $OTAmount = $_POST['OTAmount'];
    $Allowance2 = $_POST['Allowance2'];
    $TotalSalary = $_POST['TotalSalary'];
    $Advance = $_POST['Advance'];
    $SalaryTo = $_POST['SalaryTo'];
    $Mobile = $_POST['Mobile'];
    $Home = $_POST['Home'];

//Insert Query of SQL
        $query = mysql_query("INSERT INTO attendance(ID,Name,Location, Date,Category,LabourSupplier,BasicSalary,Allowance1,InTime,OutTime,Day,DayRate,Salary,OTHours,OTrate,OTAmount,Allowance2,TotalSalary,Advance,SalaryToHand, Mobile, Home) VALUES ('$ID','$Name','$Location' ,'$Date', '$Category','$LabourSupplier','$BasicSalary','$Allowance1','$InTime','$OutTime','$Day','$DayRate','$Salary','$OtHours','$OTrate','$OTAmount','$Allowance2','$TotalSalary','$Advance','$SalaryTo','$Mobile','$Home')",$connection);

        }
    ?>
</code>```

this is the html code of the form.

```<code><form id="details" action="" method="POST">

    <fieldset> ID:
        <input class="input" type="text" id="id" name="ID" value="" />
      </fieldset>
    <fieldset> Name:
      <input class="input" type="text" id="name" name="Name" value="" />
    </fieldset>
    <fieldset> Location:
      <input class="input" type="text" id="location" name="Location" value="" />
    </fieldset>
    <fieldset> Date:
      <input class="input" type="text" id="date" name="Date" value="" />
    </fieldset>
    <fieldset> Category:
      <input class="input" type="text" id="category" name="Category" value="" />
    </fieldset>
    <fieldset> Labour Supplier:
     <input class="input" type="text" id="labsupp" name="LabourSupplier" value="" />
    </fieldset>
    <fieldset> Basic Salary:
      <input class="input" type="text" id="bsalary" name="BasicSalary" value="" />
    </fieldset>
    <fieldset> Allowance I:
      <input class="input" type="text" id="all1" name="Allowance1" value="" />
    </fieldset>
    <fieldset> In-Time:
     <input class="input" type="text" name="InTime" id="intime" value="" />
    </fieldset>
    <fieldset>Out-Time:
      <input class="input" type="text" name="OutTime" id="outtime" value="" />
    </fieldset>
    <fieldset> Day:
     <input class="input" type="text" id="day" name="Day" value="" />
    </fieldset>
    <fieldset> Day Rate:
    <input class="input" type="text" id="dayrate" name="DayRate" value="" />
    </fieldset>
    <fieldset>Salary:
     <input class="input" type="text" id="salary" name="Salary" value="" />
    </fieldset>
    <fieldset>OT Hours:
     <input class="input" type="text" id="othours" name="OtHours" value="" />
    </fieldset>
    <fieldset>OT Rate:
     <input class="input" type="text" id="otrate" name="OTrate" value="" />
    </fieldset>
    <fieldset> OT Amount:
      <input class="input" type="text" id="otamount" name="OTAmount" value="" />
    </fieldset>
    <fieldset> Allownace II:
      <input class="input" type="text" id="allowance2" name="Allowance2" value="" />
    </fieldset>
    <fieldset> Total Salary:
      <input class="input" type="text" id="totalsalary" name="TotalSalary" value="" />
    </fieldset>
    <fieldset> Advance:
      <input class="input" type="text" id="advance" name="Advance" value="" />
    </fieldset>
    <fieldset> Salary To Hand:
      <input class="input" type="text" id="salaryto" name="SalaryTo" value="" />
    </fieldset>
    <fieldset> Mobile:
      <input class="input" type="text" id="mobile" name="Mobile" value="" />
    </fieldset>
    <fieldset> Home:
      <input class="input" type="text" id="home" name="Home" value="" />
    </fieldset> <br>
    <fieldset >
      <button name="submit" type="submit" id="submit">Insert</button>
      <button name="update" type="submit" id="update">Update</button>
      <button name="delete" type="delete" id="delete">Delete</button>
      <button onclick="win();" name="Back" type="back" id="details-back">Back</button>
    </fieldset>

  </form>
</code>```

答:
Your best bet is to use ajax, which basically allows you to post the data without reloading the page (which is what clears your form fields). Details of this can be found here: https://api.jquery.com/jquery.post/ but a simple example is something like the below:

```<code>$.post("myscript.php", function(data) {
  alert("record added!");
});
</code>```

Alternatively when you post your data you could just check for it in each of your form fields and put it in again. So for example with your ID field you can do something like:

```<code><input class="input" type="text" id="id" name="ID" value="<?php isset($_POST['ID']) ? $_POST['ID'] : false; ?>" />
</code>```

You may need to do something like this anyway if you have any sort of error checking on your form, so if they enter something invalid and it fails to insert you want to retain all of the field data rather than clear it.

Body:
In this form when you click on a record from the table that data appears on the form in left. When I click on the Insert button, data gets stored in the database and disappears from the form like there's no record. Is there any way to make the records stay even after I hit the Insert button.

this is my php code for the insertion.

<?php

    if(isset($_POST['submit'])){

    $ID = $_POST['ID'];
    $Name = $_POST['Name'];
    $Location = $_POST['Location'];
    $Date = $_POST['Date'];
    $Category = $_POST['Category'];
    $LabourSupplier = $_POST['LabourSupplier'];
    $BasicSalary = $_POST['BasicSalary'];
    $Allowance1 = $_POST['Allowance1'];
    $InTime = $_POST['InTime'];
    $OutTime = $_POST['OutTime'];
    $Day = $_POST['Day'];
    $DayRate = $_POST['DayRate'];
    $Salary = $_POST['Salary'];
    $OtHours = $_POST['OtHours'];
    $OTrate = $_POST['OTrate'];
    $OTAmount = $_POST['OTAmount'];
    $Allowance2 = $_POST['Allowance2'];
    $TotalSalary = $_POST['TotalSalary'];
    $Advance = $_POST['Advance'];
    $SalaryTo = $_POST['SalaryTo'];
    $Mobile = $_POST['Mobile'];
    $Home = $_POST['Home'];

//Insert Query of SQL
        $query = mysql_query("INSERT INTO attendance(ID,Name,Location, Date,Category,LabourSupplier,BasicSalary,Allowance1,InTime,OutTime,Day,DayRate,Salary,OTHours,OTrate,OTAmount,Allowance2,TotalSalary,Advance,SalaryToHand, Mobile, Home) VALUES ('$ID','$Name','$Location' ,'$Date', '$Category','$LabourSupplier','$BasicSalary','$Allowance1','$InTime','$OutTime','$Day','$DayRate','$Salary','$OtHours','$OTrate','$OTAmount','$Allowance2','$TotalSalary','$Advance','$SalaryTo','$Mobile','$Home')",$connection);

        }
    ?>

this is the html code of the form.

<form id="details" action="" method="POST">

    <fieldset> ID:
        <input class="input" type="text" id="id" name="ID" value="" />
      </fieldset>
    <fieldset> Name:
      <input class="input" type="text" id="name" name="Name" value="" />
    </fieldset>
    <fieldset> Location:
      <input class="input" type="text" id="location" name="Location" value="" />
    </fieldset>
    <fieldset> Date:
      <input class="input" type="text" id="date" name="Date" value="" />
    </fieldset>
    <fieldset> Category:
      <input class="input" type="text" id="category" name="Category" value="" />
    </fieldset>
    <fieldset> Labour Supplier:
     <input class="input" type="text" id="labsupp" name="LabourSupplier" value="" />
    </fieldset>
    <fieldset> Basic Salary:
      <input class="input" type="text" id="bsalary" name="BasicSalary" value="" />
    </fieldset>
    <fieldset> Allowance I:
      <input class="input" type="text" id="all1" name="Allowance1" value="" />
    </fieldset>
    <fieldset> In-Time:
     <input class="input" type="text" name="InTime" id="intime" value="" />
    </fieldset>
    <fieldset>Out-Time:
      <input class="input" type="text" name="OutTime" id="outtime" value="" />
    </fieldset>
    <fieldset> Day:
     <input class="input" type="text" id="day" name="Day" value="" />
    </fieldset>
    <fieldset> Day Rate:
    <input class="input" type="text" id="dayrate" name="DayRate" value="" />
    </fieldset>
    <fieldset>Salary:
     <input class="input" type="text" id="salary" name="Salary" value="" />
    </fieldset>
    <fieldset>OT Hours:
     <input class="input" type="text" id="othours" name="OtHours" value="" />
    </fieldset>
    <fieldset>OT Rate:
     <input class="input" type="text" id="otrate" name="OTrate" value="" />
    </fieldset>
    <fieldset> OT Amount:
      <input class="input" type="text" id="otamount" name="OTAmount" value="" />
    </fieldset>
    <fieldset> Allownace II:
      <input class="input" type="text" id="allowance2" name="Allowance2" value="" />
    </fieldset>
    <fieldset> Total Salary:
      <input class="input" type="text" id="totalsalary" name="TotalSalary" value="" />
    </fieldset>
    <fieldset> Advance:
      <input class="input" type="text" id="advance" name="Advance" value="" />
    </fieldset>
    <fieldset> Salary To Hand:
      <input class="input" type="text" id="salaryto" name="SalaryTo" value="" />
    </fieldset>
    <fieldset> Mobile:
      <input class="input" type="text" id="mobile" name="Mobile" value="" />
    </fieldset>
    <fieldset> Home:
      <input class="input" type="text" id="home" name="Home" value="" />
    </fieldset>

    <fieldset >
      <button name="submit" type="submit" id="submit">Insert</button>
      <button name="update" type="submit" id="update">Update</button>
      <button name="delete" type="delete" id="delete">Delete</button>
      <button onclick="win();" name="Back" type="back" id="details-back">Back</button>
    </fieldset>

  </form>

Body:
Your best bet is to use ajax, which basically allows you to post the data without reloading the page (which is what clears your form fields). Details of this can be found here: https://api.jquery.com/jquery.post/ but a simple example is something like the below:

$.post("myscript.php", function(data) {
  alert("record added!");
});

Alternatively when you post your data you could just check for it in each of your form fields and put it in again. So for example with your ID field you can do something like:

<input class="input" type="text" id="id" name="ID" value="<?php isset($_POST['ID']) ? $_POST['ID'] : false; ?>" />

You may need to do something like this anyway if you have any sort of error checking on your form, so if they enter something invalid and it fails to insert you want to retain all of the field data rather than clear it.


问:
How to edit the variables of a php file with another php file
Ok so I want to do something similar to how Simple Machine Forum edits some variable within the Admin panel on the forum. For instance
I have a settings.php file. I want tool.php to open and find all declared php variables in the settings.php like $background_color='Orange' and output in tools.php Background Color: Orange inside of a form tag that, once changed to 'Purple' and submitted, replaces 'Orange' with 'Purple' and now if i open 'settings.php' the variable inside the file is now "$background_color='Purple'" without having to go in an manually edit it. I can just submit the new data for the variable and replace the old.

答:
To keep the data persistent, you will need to store data in a database or separate file e.g. JSON file. Then you can use that data everywhere it is needed.

Here is an example using a JSON file.

setting_variables.json:

```<code>{
    "background": "red",
    "color": "white"
}
</code>```

settings.php

```<code>$settings = json_decode(file_get_contents("settings_variables.json"), true);
$background = $settings['background'];
</code>```

tools.php

```<code>include ("settings.php");

// If form is posted
if(isset($_POST['submit'])){
    /* Updating variables in JSON file*/

    //Get settings_json file
    $setting_vars = json_decode(file_get_contents('settings_variables.json'), true);

    // Update variable
    $background = $setting_vars['background'] = $_POST['color'];

    // Store variable value to JSON file
    file_put_contents("settings_variables.json", json_encode($setting_vars));
}

?>

<form method="post" <?php echo "style='background-color:".$background . "'"; ?>>
    <select name="color">
    <option value="red">red</option>
    <option value="blue">blue</option>
    <option value="orange">orange</option>
    <option value="yellow">yellow</option>
    <option value="purple">purple</option>
  </select>
  <input type="submit" name="submit"/>
</form>
</code>```

Body:
To keep the data persistent, you will need to store data in a database or separate file e.g. JSON file. Then you can use that data everywhere it is needed.

Here is an example using a JSON file.

setting_variables.json:

{
    "background": "red",
    "color": "white"
}

settings.php

$settings = json_decode(file_get_contents("settings_variables.json"), true);
$background = $settings['background'];

tools.php

include ("settings.php");

// If form is posted
if(isset($_POST['submit'])){
    /* Updating variables in JSON file*/

    //Get settings_json file
    $setting_vars = json_decode(file_get_contents('settings_variables.json'), true);

    // Update variable
    $background = $setting_vars['background'] = $_POST['color'];

    // Store variable value to JSON file
    file_put_contents("settings_variables.json", json_encode($setting_vars));
}

?>

<form method="post" <?php echo "style='background-color:".$background . "'"; ?>>
    <select name="color">
    <option value="red">red</option>
    <option value="blue">blue</option>
    <option value="orange">orange</option>
    <option value="yellow">yellow</option>
    <option value="purple">purple</option>
  </select>
  <input type="submit" name="submit"/>
</form>


问:
Include functions
EDIT
Due to the overwhelming amount of advice I have received, I have fixed my problem. (After realizing the horrible php code I had written.) :D

Thanks to all!

Is there a reason that a function that is inside an included php file won't work on the parent page? I have two functions inside a php file that is included at the top of the page. However, when I try to call the function, it doesn't do anything. Here's the basic layout:

Main page:

```<code><?php include 'includes/header.php'; ?>
<?php getPosts();?>
<div>Some HTML Code</div>
<?php endPosts(); ?>
</code>```

Header.php

```<code>function getPosts() {
$result = mysql_query("SELECT * FROM posts order by id desc") or die(mysql_error());
     while($row = mysql_fetch_array($result)) {
};
function endPosts() {
} /*End while statement */
};
</code>```

Any idea why this won't work? I'm getting a blank white screen right now.

答:
I don't think that kind of stripping in functions will work. Aren't you getting errors from the PHP parser?

You should use something like this:

```<code><?php $res = getPosts() ?>
<?php while ($item = mysql_fetch_array($res)): ?>
  <div>Some HTML code</div>
<?php endwhile; ?>
</code>```

With your getPosts() function like:

```<code>function getPosts()
{
  $query = mysql_query("SELECT * FROM posts order by id desc");

  if (!$query) die('MySQL error');

  return $query;
}
</code>```

ContentLicense: CC BY-SA 2.5

Title: Include functions

Body:
EDIT
Due to the overwhelming amount of advice I have received, I have fixed my problem. (After realizing the horrible php code I had written.) :D

Thanks to all!

Is there a reason that a function that is inside an included php file won't work on the parent page? I have two functions inside a php file that is included at the top of the page. However, when I try to call the function, it doesn't do anything. Here's the basic layout:

Main page:

<?php include 'includes/header.php'; ?>
<?php getPosts();?>

Some HTML Code

<?php endPosts(); ?>

Header.php

function getPosts() {
$result = mysql_query("SELECT * FROM posts order by id desc") or die(mysql_error());
     while($row = mysql_fetch_array($result)) {
};
function endPosts() {
} /*End while statement */
};

Any idea why this won't work? I'm getting a blank white screen right now.

Body:
I don't think that kind of stripping in functions will work. Aren't you getting errors from the PHP parser?

You should use something like this:

<?php $res = getPosts() ?>
<?php while ($item = mysql_fetch_array($res)): ?>
  <div>Some HTML code</div>
<?php endwhile; ?>

With your getPosts() function like:

function getPosts()
{
  $query = mysql_query("SELECT * FROM posts order by id desc");

  if (!$query) die('MySQL error');

  return $query;
}


问:
How to have a popup read and display information from a GeoJson file (LEAFLET)
I am trying to make an interactive map of trails my company owns for my companies website.

I have markers displayed on all the trailheads and I want them to display a popup of certain information located inside of a GeoJson file.

Here is my HTML Code

<!DOCTYPE html>

  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Map</title>

  <link rel="stylesheet" href="lib/leaflet/leaflet.css" />

  <link href='https://api.mapbox.com/mapbox-gl-js/v0.38.0/mapbox-gl.css' rel='stylesheet' />

 Map

```

The GeoJson file is quite large so I will attach it into a mediafire download (along with the HTML, just incase you need it)

Index.html

Trailheads GeoJson file

答:
Assuming that trailheads.js is a valid jsonp file, you should specify for each feature what information you will display. If you look at the leaflet docs, there's an option: 'onEachFeature' which you can use.

```<code>var trailheadsLayer = L.geoJson(trailheads, {
  onEachFeature: function(layer, feature) {
    feature.bindPopup('popup content');
  }
});
</code>```

You can change 'popup content' for a property of your geoJSON, e.g. 'feature.properties.name'.

ContentLicense: CC BY-SA 4.0

Body:
I am trying to make an interactive map of trails my company owns for my companies website.

I have markers displayed on all the trailheads and I want them to display a popup of certain information located inside of a GeoJson file.

Here is my HTML Code

<!DOCTYPE html>

  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Map</title>

  <link rel="stylesheet" href="lib/leaflet/leaflet.css" />

  <link href='https://api.mapbox.com/mapbox-gl-js/v0.38.0/mapbox-gl.css' rel='stylesheet' />

 Map

The GeoJson file is quite large so I will attach it into a mediafire download (along with the HTML, just incase you need it)

Index.html

Trailheads GeoJson file

Body:
Assuming that trailheads.js is a valid jsonp file, you should specify for each feature what information you will display. If you look at the leaflet docs, there's an option: 'onEachFeature' which you can use.

var trailheadsLayer = L.geoJson(trailheads, {
  onEachFeature: function(layer, feature) {
    feature.bindPopup('popup content');
  }
});

You can change 'popup content' for a property of your geoJSON, e.g. 'feature.properties.name'.


问:
Base R plot gradient line, possible?
Is it possible to make a ggplot-esque gradient line, like so, but in base R?

My best attempt is this

It's apparently possible to color dots in multiple colors, but not lines, like so:

```<code>require(colorRamps)

# This initiates an empty plot
plot(x = Sim_Tracks$x,
     y = Sim_Tracks$y,
     xlim = c(min(raster_dir$x), max(raster_dir$x)),
     ylim = c(min(raster_dir$y), max(raster_dir$y)),
     xlab = "",
     ylab = "",
     type = "n",
     asp = 1)

# This adds the line for the track, which apparently is impossible to give more than one color
lines(x = Sim_Tracks$x,
      y = Sim_Tracks$y,
      type = "l",
      lwd = 1,
      col = "grey30")

# This adds a dot for every data point, which CAN be colored.
points(x = Sim_Tracks$x,
       y = Sim_Tracks$y,
       type = "p",  #p
       pch = 20,
       cex = 0.4,
       col = matlab.like2(length(Sim_Tracks$frame)))
</code>```

Finally, if you need, here's some mock data:

```<code>structure(list(track_id = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Track 1", class = "factor"),
    track_length = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Track length:  50", class = "factor"),
    frame = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
    45, 46, 47, 48, 49), x = c(-0.823120271836757, -1.0540205585043,
    -2.24524898310529, -2.49804924270122, -2.04337907770748,
    -0.71182638228976, 0.0552406597736446, 0.837902269521245,
    1.14555083338094, 1.61485649207271, 2.32675075246972, 1.77460399339182,
    0.591539463396913, 1.31150904469615, 2.45115630420804, 3.47624837807415,
    4.93388595879012, 6.36734872479006, 7.2537532065069, 8.85209379145564,
    9.26576425423642, 7.8354233429016, 7.50966602231002, 7.8300462766058,
    7.70517484751459, 7.56126498370911, 7.61513799406078, 8.11448589302167,
    6.54421019891895, 6.25450645400463, 6.77798675689718, 6.28083745096866,
    5.72133770977047, 6.72517343463326, 7.07822425754604, 6.68399537519387,
    5.19570030405409, 6.3009100137371, 5.03670095894547, 7.39621258921778,
    6.74605505325002, 8.67274478498824, 10.7595870758823, 11.6620548220588,
    12.6043518173776, 11.4373355039149, 11.7420435650284, 11.993176667951,
    12.0940143565155, 9.30535695995201), y = c(0.930103140017403,
    0.83523651582367, 1.04935104116715, 1.49692422249737, 2.58661689607573,
    2.70009371265145, 1.88094058262706, 2.73644396447942, 3.74552207306143,
    3.24566753468233, 3.86804664100169, 3.79259650171041, 3.25788243807157,
    3.43537019996413, 3.49413084580058, 3.28724643191944, 4.93279754215246,
    4.30201934697842, 6.02705795338077, 6.46372463359186, 4.83485974715237,
    4.98572660233063, 4.03462627496725, 2.90778119988415, 2.67992326433969,
    2.92114212274953, 3.34307788832756, 3.58790189484841, 4.68389763710923,
    2.79947174313274, 3.19140102348251, 3.64245983909256, 3.66559854337892,
    4.36263034563625, 4.2336547272965, 4.49050510921861, 4.39885291278005,
    3.19131121689556, 2.95953127833572, 2.48043764647912, 0.650316331872992,
    0.576351488782491, 0.495282114032306, 0.990831170758003,
    1.81651448446863, 0.894084551162406, 2.94196592812597, 2.27655119887946,
    2.27358041607369, 1.35356935845552), dx = c(0, -0.230900286667547,
    -1.19122842460099, -0.252800259595928, 0.45467016499374,
    1.33155269541772, 0.767067042063404, 0.7826616097476, 0.307648563859696,
    0.46930565869177, 0.711894260397012, -0.552146759077906,
    -1.1830645299949, 0.71996958129924, 1.13964725951188, 1.02509207386611,
    1.45763758071597, 1.43346276599995, 0.886404481716838, 1.59834058494874,
    0.413670462780775, -1.43034091133481, -0.325757320591584,
    0.320380254295776, -0.124871429091202, -0.143909863805481,
    0.0538730103516682, 0.499347898960888, -1.57027569410272,
    -0.289703744914322, 0.523480302892544, -0.497149305928512,
    -0.559499741198191, 1.00383572486279, 0.353050822912783,
    -0.394228882352175, -1.48829507113977, 1.10520970968301,
    -1.26420905479163, 2.35951163027231, -0.650157535967769,
    1.92668973173822, 2.08684229089405, 0.902467746176468, 0.942296995318797,
    -1.16701631346267, 0.30470806111355, 0.251133102922564, 0.100837688564541,
    -2.78865739656353), dy = c(0, -0.0948666241937332, 0.214114525343483,
    0.447573181330215, 1.08969267357836, 0.11347681657572, -0.81915313002439,
    0.855503381852357, 1.00907810858201, -0.49985453837909, 0.622379106319354,
    -0.0754501392912799, -0.534714063638843, 0.177487761892567,
    0.0587606458364491, -0.206884413881141, 1.64555111023302,
    -0.630778195174043, 1.72503860640235, 0.436666680211095,
    -1.62886488643949, 0.150866855178265, -0.951100327363388,
    -1.1268450750831, -0.227857935544455, 0.241218858409837,
    0.42193576557803, 0.244824006520855, 1.09599574226081, -1.88442589397648,
    0.391929280349769, 0.451058815610044, 0.0231387042863664,
    0.697031802257325, -0.128975618339743, 0.256850381922106,
    -0.0916521964385622, -1.20754169588449, -0.231779938559836,
    -0.479093631856603, -1.83012131460613, -0.0739648430905018,
    -0.0810693747501843, 0.495549056725697, 0.825683313710626,
    -0.922429933306223, 2.04788137696356, -0.665414729246509,
    -0.00297078280576946, -0.920011057618168), steplength = c(0,
    0.249628962200043, 1.2103182182965, 0.514032804301261, 1.18074344452374,
    1.33637927572017, 1.12223157033148, 1.1595021482229, 1.05493424821852,
    0.685640110275274, 0.945594622430292, 0.557277998021911,
    1.29829149730915, 0.741524176017098, 1.14116111466001, 1.04576045087299,
    2.19830520472127, 1.56610875516844, 1.93945123650641, 1.6569159348322,
    1.68057254233574, 1.43827533199645, 1.0053405714631, 1.17150472921865,
    0.259830930787426, 0.280885361941589, 0.42536113070927, 0.556135881206722,
    1.91493405174789, 1.90656476672219, 0.653942037425304, 0.671276014411908,
    0.559977999600783, 1.22210453557332, 0.375871778250925, 0.470519426139004,
    1.49111446371194, 1.63696226275293, 1.28528069857753, 2.407659826777,
    1.9421763173696, 1.9281089493073, 2.08841638343179, 1.02957122167947,
    1.25286733612422, 1.48754968244672, 2.07042631760267, 0.711227528489807,
    0.100881440243081, 2.93649968866816), direction = c(0, -157.664426880079,
    169.810310566022, 119.458821730763, 67.3518463233156, 4.87105832947719,
    -46.8807232140758, 47.546006533313, 73.0445415336028, -46.8054213691044,
    41.1618312257487, -172.218799567976, -155.678282430464, 13.8484943961173,
    2.9515784556039, -11.4101827098002, 48.4653132648651, -23.7513221300862,
    62.8038083429716, 15.2803269004432, -75.7502814970167, 173.978924393633,
    -108.90662633776, -74.1286928212514, -118.723762406006, 120.820073224714,
    82.7238098702714, 26.1181332820139, 145.086350106974, -98.7399862128212,
    36.822168176114, 137.78284231448, 177.631821865943, 34.7748916508859,
    -20.0681296088653, 146.914709178072, -176.476061111604, -47.5335058080855,
    -169.610779191333, -11.4777430060655, -109.55777502371, -2.19848231894698,
    -2.22470021358901, 28.7713844879839, 41.2263111129792, -141.676544207096,
    81.5369449678388, -69.3230725333515, -1.68750492967911, -161.741665970814
    )), .Names = c("track_id", "track_length", "frame", "x",
"y", "dx", "dy", "steplength", "direction"), row.names = c(NA,
-50L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "track_id", drop = TRUE, indices = list(
    0:49), group_sizes = 50L, biggest_group_size = 50L, labels = structure(list(
    track_id = structure(1L, .Label = "Track 1", class = "factor")), row.names = c(NA,
-1L), class = "data.frame", vars = "track_id", drop = TRUE, .Names = "track_id"))
</code>```

答:
The segments function does what you want, for example like:

```<code>segments(x0 = head(Sim_Tracks$x,-1),
         y0 = head(Sim_Tracks$y,-1),
         x1 = tail(Sim_Tracks$x,-1),
         y1 = tail(Sim_Tracks$y,-1),
         lwd = 1,
         col = matlab.like2(length(Sim_Tracks$frame)-1))
</code>```

Note that there are n-1 lines for n points, so I've divided the colour ramp up into n-1 colours, you could also match to the point colour at the start or end of the line with a small change to the col argument.

Title: Base R plot gradient line, possible?

Body:
Is it possible to make a ggplot-esque gradient line, like so, but in base R?

My best attempt is this

It's apparently possible to color dots in multiple colors, but not lines, like so:

require(colorRamps)

# This initiates an empty plot
plot(x = Sim_Tracks$x,
     y = Sim_Tracks$y,
     xlim = c(min(raster_dir$x), max(raster_dir$x)),
     ylim = c(min(raster_dir$y), max(raster_dir$y)),
     xlab = "",
     ylab = "",
     type = "n",
     asp = 1)

# This adds the line for the track, which apparently is impossible to give more than one color
lines(x = Sim_Tracks$x,
      y = Sim_Tracks$y,
      type = "l",
      lwd = 1,
      col = "grey30")

# This adds a dot for every data point, which CAN be colored.
points(x = Sim_Tracks$x,
       y = Sim_Tracks$y,
       type = "p",  #p
       pch = 20,
       cex = 0.4,
       col = matlab.like2(length(Sim_Tracks$frame)))

Finally, if you need, here's some mock data:

structure(list(track_id = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Track 1", class = "factor"),
    track_length = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Track length:  50", class = "factor"),
    frame = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
    45, 46, 47, 48, 49), x = c(-0.823120271836757, -1.0540205585043,
    -2.24524898310529, -2.49804924270122, -2.04337907770748,
    -0.71182638228976, 0.0552406597736446, 0.837902269521245,
    1.14555083338094, 1.61485649207271, 2.32675075246972, 1.77460399339182,
    0.591539463396913, 1.31150904469615, 2.45115630420804, 3.47624837807415,
    4.93388595879012, 6.36734872479006, 7.2537532065069, 8.85209379145564,
    9.26576425423642, 7.8354233429016, 7.50966602231002, 7.8300462766058,
    7.70517484751459, 7.56126498370911, 7.61513799406078, 8.11448589302167,
    6.54421019891895, 6.25450645400463, 6.77798675689718, 6.28083745096866,
    5.72133770977047, 6.72517343463326, 7.07822425754604, 6.68399537519387,
    5.19570030405409, 6.3009100137371, 5.03670095894547, 7.39621258921778,
    6.74605505325002, 8.67274478498824, 10.7595870758823, 11.6620548220588,
    12.6043518173776, 11.4373355039149, 11.7420435650284, 11.993176667951,
    12.0940143565155, 9.30535695995201), y = c(0.930103140017403,
    0.83523651582367, 1.04935104116715, 1.49692422249737, 2.58661689607573,
    2.70009371265145, 1.88094058262706, 2.73644396447942, 3.74552207306143,
    3.24566753468233, 3.86804664100169, 3.79259650171041, 3.25788243807157,
    3.43537019996413, 3.49413084580058, 3.28724643191944, 4.93279754215246,
    4.30201934697842, 6.02705795338077, 6.46372463359186, 4.83485974715237,
    4.98572660233063, 4.03462627496725, 2.90778119988415, 2.67992326433969,
    2.92114212274953, 3.34307788832756, 3.58790189484841, 4.68389763710923,
    2.79947174313274, 3.19140102348251, 3.64245983909256, 3.66559854337892,
    4.36263034563625, 4.2336547272965, 4.49050510921861, 4.39885291278005,
    3.19131121689556, 2.95953127833572, 2.48043764647912, 0.650316331872992,
    0.576351488782491, 0.495282114032306, 0.990831170758003,
    1.81651448446863, 0.894084551162406, 2.94196592812597, 2.27655119887946,
    2.27358041607369, 1.35356935845552), dx = c(0, -0.230900286667547,
    -1.19122842460099, -0.252800259595928, 0.45467016499374,
    1.33155269541772, 0.767067042063404, 0.7826616097476, 0.307648563859696,
    0.46930565869177, 0.711894260397012, -0.552146759077906,
    -1.1830645299949, 0.71996958129924, 1.13964725951188, 1.02509207386611,
    1.45763758071597, 1.43346276599995, 0.886404481716838, 1.59834058494874,
    0.413670462780775, -1.43034091133481, -0.325757320591584,
    0.320380254295776, -0.124871429091202, -0.143909863805481,
    0.0538730103516682, 0.499347898960888, -1.57027569410272,
    -0.289703744914322, 0.523480302892544, -0.497149305928512,
    -0.559499741198191, 1.00383572486279, 0.353050822912783,
    -0.394228882352175, -1.48829507113977, 1.10520970968301,
    -1.26420905479163, 2.35951163027231, -0.650157535967769,
    1.92668973173822, 2.08684229089405, 0.902467746176468, 0.942296995318797,
    -1.16701631346267, 0.30470806111355, 0.251133102922564, 0.100837688564541,
    -2.78865739656353), dy = c(0, -0.0948666241937332, 0.214114525343483,
    0.447573181330215, 1.08969267357836, 0.11347681657572, -0.81915313002439,
    0.855503381852357, 1.00907810858201, -0.49985453837909, 0.622379106319354,
    -0.0754501392912799, -0.534714063638843, 0.177487761892567,
    0.0587606458364491, -0.206884413881141, 1.64555111023302,
    -0.630778195174043, 1.72503860640235, 0.436666680211095,
    -1.62886488643949, 0.150866855178265, -0.951100327363388,
    -1.1268450750831, -0.227857935544455, 0.241218858409837,
    0.42193576557803, 0.244824006520855, 1.09599574226081, -1.88442589397648,
    0.391929280349769, 0.451058815610044, 0.0231387042863664,
    0.697031802257325, -0.128975618339743, 0.256850381922106,
    -0.0916521964385622, -1.20754169588449, -0.231779938559836,
    -0.479093631856603, -1.83012131460613, -0.0739648430905018,
    -0.0810693747501843, 0.495549056725697, 0.825683313710626,
    -0.922429933306223, 2.04788137696356, -0.665414729246509,
    -0.00297078280576946, -0.920011057618168), steplength = c(0,
    0.249628962200043, 1.2103182182965, 0.514032804301261, 1.18074344452374,
    1.33637927572017, 1.12223157033148, 1.1595021482229, 1.05493424821852,
    0.685640110275274, 0.945594622430292, 0.557277998021911,
    1.29829149730915, 0.741524176017098, 1.14116111466001, 1.04576045087299,
    2.19830520472127, 1.56610875516844, 1.93945123650641, 1.6569159348322,
    1.68057254233574, 1.43827533199645, 1.0053405714631, 1.17150472921865,
    0.259830930787426, 0.280885361941589, 0.42536113070927, 0.556135881206722,
    1.91493405174789, 1.90656476672219, 0.653942037425304, 0.671276014411908,
    0.559977999600783, 1.22210453557332, 0.375871778250925, 0.470519426139004,
    1.49111446371194, 1.63696226275293, 1.28528069857753, 2.407659826777,
    1.9421763173696, 1.9281089493073, 2.08841638343179, 1.02957122167947,
    1.25286733612422, 1.48754968244672, 2.07042631760267, 0.711227528489807,
    0.100881440243081, 2.93649968866816), direction = c(0, -157.664426880079,
    169.810310566022, 119.458821730763, 67.3518463233156, 4.87105832947719,
    -46.8807232140758, 47.546006533313, 73.0445415336028, -46.8054213691044,
    41.1618312257487, -172.218799567976, -155.678282430464, 13.8484943961173,
    2.9515784556039, -11.4101827098002, 48.4653132648651, -23.7513221300862,
    62.8038083429716, 15.2803269004432, -75.7502814970167, 173.978924393633,
    -108.90662633776, -74.1286928212514, -118.723762406006, 120.820073224714,
    82.7238098702714, 26.1181332820139, 145.086350106974, -98.7399862128212,
    36.822168176114, 137.78284231448, 177.631821865943, 34.7748916508859,
    -20.0681296088653, 146.914709178072, -176.476061111604, -47.5335058080855,
    -169.610779191333, -11.4777430060655, -109.55777502371, -2.19848231894698,
    -2.22470021358901, 28.7713844879839, 41.2263111129792, -141.676544207096,
    81.5369449678388, -69.3230725333515, -1.68750492967911, -161.741665970814
    )), .Names = c("track_id", "track_length", "frame", "x",
"y", "dx", "dy", "steplength", "direction"), row.names = c(NA,
-50L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "track_id", drop = TRUE, indices = list(
    0:49), group_sizes = 50L, biggest_group_size = 50L, labels = structure(list(
    track_id = structure(1L, .Label = "Track 1", class = "factor")), row.names = c(NA,
-1L), class = "data.frame", vars = "track_id", drop = TRUE, .Names = "track_id"))

Body:
The segments function does what you want, for example like:

segments(x0 = head(Sim_Tracks$x,-1),
         y0 = head(Sim_Tracks$y,-1),
         x1 = tail(Sim_Tracks$x,-1),
         y1 = tail(Sim_Tracks$y,-1),
         lwd = 1,
         col = matlab.like2(length(Sim_Tracks$frame)-1))

Note that there are n-1 lines for n points, so I've divided the colour ramp up into n-1 colours, you could also match to the point colour at the start or end of the line with a small change to the col argument.


答:
You can use a loop or mapply for this:

```<code>mapply(function(x, y, col) lines(x, y, col = col),
       x = rbind.data.frame(Sim_Tracks$x, dplyr::lag(Sim_Tracks$x)),
       y = rbind.data.frame(Sim_Tracks$y, dplyr::lag(Sim_Tracks$y)),
       col = matlab.like2(length(Sim_Tracks$frame)))
</code>```

Title: Base R plot gradient line, possible?

Body:
You can use a loop or mapply for this:

mapply(function(x, y, col) lines(x, y, col = col),
       x = rbind.data.frame(Sim_Tracks$x, dplyr::lag(Sim_Tracks$x)),
       y = rbind.data.frame(Sim_Tracks$y, dplyr::lag(Sim_Tracks$y)),
       col = matlab.like2(length(Sim_Tracks$frame)))


问:
C# XAML MVVM Treeview control Data Binding
I can not display the item list.
What am I doing wrong?

XAML(View):

```<code><Grid.DataContext>
     <vm:MainViewModel />
</Grid.DataContext>

<Grid.Resources>
     <DataTemplate x:Key="Remedy">
       <TextBlock Text="{Binding Titulo}" />
     </DataTemplate>

     <HierarchicalDataTemplate x:Key="Laboratorio"
                              ItemTemplate="{StaticResource Remedy}"
                              ItemsSource="{Binding Items}">
         <TextBlock Text="{Binding Titulo}" />
     </HierarchicalDataTemplate>
     <HierarchicalDataTemplate x:Key="Root"
                               ItemTemplate="{StaticResource Laboratorio}"
                               ItemsSource="{Binding Items}">
         <TextBlock Text="{Binding Titulo}" />
     </HierarchicalDataTemplate>

</Grid.Resources>

<TreeView x:Name="dirR"
          ItemsSource="{Binding Path=Arbol}"
          ItemTemplate="{StaticResource Root}">
</TreeView>
</code>```

C# (ViewModel):

```<code>class MainViewModel:INotifyPropertyChanged
{
   private TreeItem _arbol = new TreeItem("Remedys");
   public TreeItem Arbol
   {
      set
      {
         _arbol = value;
         OnPropertyChanged("Arbol");
      }
         get { return _arbol; }
   }

   public MainViewModel()
   {
       //Populate Arbol
       ...
    }
}
</code>```

C# (Model):

```<code>public class TreeItem:INotifyPropertyChanged
{
    private String _titulo;
    private ObservableCollection<TreeItem> _items;
    public String Titulo
    {
        get { return _titulo; }
        set
        {
            _titulo = value;
            OnPropertyChanged("Titulo");
        }
    }
    public ObservableCollection<TreeItem> Items
    {
        get { return _items; }
        set
        {
            _items = value;
            OnPropertyChanged("Items");
        }
    }
    public TreeItem(String __titulo)
    {
        Titulo = __titulo;
    }
</code>```

C# (MainWindow v1):

```<code>public MainWindow()
{
    InitializeComponent();

}
</code>```

C# (MainWindow v2) This version works ok but I do not like it because there is code dependency between View and Viewmodel

```<code>public MainWindow()
{
    InitializeComponent();

    MainViewModel vm = new MainViewModel();
    dirR.Items.Add(vm.Arbol);
}
</code>```

答:
You can only bind a value to ItemsSource which implements IEnumerable. Generally spoken you have to bind a collection to ItemsSource.

Change your MainViewModel to

```<code>class MainViewModel:INotifyPropertyChanged
{
   private ObservableCollection<TreeItem> _arbol =
       new ObservableCollection<TreeItem>(
           new List<TreeItem>
           {
               new TreeItem("Remedys")
           } );
   public ObservableCollection<TreeItem> Arbol
   {
      set
      {
         _arbol = value;
         OnPropertyChanged("Arbol");
      }
         get { return _arbol; }
   }

   public MainViewModel()
   {
       //Populate Arbol
       ...
    }
}
</code>```

Body:
I can not display the item list.
What am I doing wrong?

XAML(View):

<Grid.DataContext>
     <vm:MainViewModel />
</Grid.DataContext>

<Grid.Resources>
     <DataTemplate x:Key="Remedy">
       <TextBlock Text="{Binding Titulo}" />
     </DataTemplate>

     <HierarchicalDataTemplate x:Key="Laboratorio"
                              ItemTemplate="{StaticResource Remedy}"
                              ItemsSource="{Binding Items}">
         <TextBlock Text="{Binding Titulo}" />
     </HierarchicalDataTemplate>
     <HierarchicalDataTemplate x:Key="Root"
                               ItemTemplate="{StaticResource Laboratorio}"
                               ItemsSource="{Binding Items}">
         <TextBlock Text="{Binding Titulo}" />
     </HierarchicalDataTemplate>

</Grid.Resources>

<TreeView x:Name="dirR"
          ItemsSource="{Binding Path=Arbol}"
          ItemTemplate="{StaticResource Root}">
</TreeView>

C# (ViewModel):

class MainViewModel:INotifyPropertyChanged
{
   private TreeItem _arbol = new TreeItem("Remedys");
   public TreeItem Arbol
   {
      set
      {
         _arbol = value;
         OnPropertyChanged("Arbol");
      }
         get { return _arbol; }
   }

   public MainViewModel()
   {
       //Populate Arbol
       ...
    }
}

C# (Model):

public class TreeItem:INotifyPropertyChanged
{
    private String _titulo;
    private ObservableCollection<TreeItem> _items;
    public String Titulo
    {
        get { return _titulo; }
        set
        {
            _titulo = value;
            OnPropertyChanged("Titulo");
        }
    }
    public ObservableCollection<TreeItem> Items
    {
        get { return _items; }
        set
        {
            _items = value;
            OnPropertyChanged("Items");
        }
    }
    public TreeItem(String __titulo)
    {
        Titulo = __titulo;
    }

C# (MainWindow v1):

public MainWindow()
{
    InitializeComponent();

}

C# (MainWindow v2) This version works ok but I do not like it because there is code dependency between View and Viewmodel

public MainWindow()
{
    InitializeComponent();

    MainViewModel vm = new MainViewModel();
    dirR.Items.Add(vm.Arbol);
}

Body:
You can only bind a value to ItemsSource which implements IEnumerable. Generally spoken you have to bind a collection to ItemsSource.

Change your MainViewModel to

class MainViewModel:INotifyPropertyChanged
{
   private ObservableCollection<TreeItem> _arbol =
       new ObservableCollection<TreeItem>(
           new List<TreeItem>
           {
               new TreeItem("Remedys")
           } );
   public ObservableCollection<TreeItem> Arbol
   {
      set
      {
         _arbol = value;
         OnPropertyChanged("Arbol");
      }
         get { return _arbol; }
   }

   public MainViewModel()
   {
       //Populate Arbol
       ...
    }
}


问:
Full text search does not work if stop word is included even though stop word list is empty
I would like to be able to search every word so I have cleared the stop word list. Than I have rebuilt the index. But unfortunately if I type in a search expression with stop word in it it still returns no row. If I leave out just the stop word I do get the results. E.g. "double wear stay in place" - no result, "double wear stay place" - I get the results that actually contain "in" as well.

Does anyone know why this can be? I am using SQL Server 2012 Express.

Thanks  a lot!

答:
In case anyone is interested, I fleshed out the check association query in apolka's answer to give more legible results:

```<code>--Check the association:
SELECT
    ft_c.name AS [Catalog],
    s.name AS [Schema],
    o.name AS [Table],
    [StopList] =
    CASE
        WHEN ft_i.stoplist_id IS NULL THEN 'None'
        ELSE ISNULL(ft_sl.NAME, 'System')
    END
FROM
    sys.fulltext_indexes AS ft_i LEFT OUTER JOIN
    sys.fulltext_stoplists AS ft_sl ON ft_sl.stoplist_id = ft_i.stoplist_id INNER JOIN
    sys.fulltext_catalogs AS ft_c ON ft_c.fulltext_catalog_id = ft_i.fulltext_catalog_id INNER JOIN
    sys.objects AS o ON o.object_id = ft_i.object_id INNER JOIN
    sys.schemas AS s ON s.schema_id = o.schema_id
</code>```

So silly this stuff is missing from SSMS!

Body:
In case anyone is interested, I fleshed out the check association query in apolka's answer to give more legible results:

--Check the association:
SELECT
    ft_c.name AS [Catalog],
    s.name AS [Schema],
    o.name AS [Table],
    [StopList] =
    CASE
        WHEN ft_i.stoplist_id IS NULL THEN 'None'
        ELSE ISNULL(ft_sl.NAME, 'System')
    END
FROM
    sys.fulltext_indexes AS ft_i LEFT OUTER JOIN
    sys.fulltext_stoplists AS ft_sl ON ft_sl.stoplist_id = ft_i.stoplist_id INNER JOIN
    sys.fulltext_catalogs AS ft_c ON ft_c.fulltext_catalog_id = ft_i.fulltext_catalog_id INNER JOIN
    sys.objects AS o ON o.object_id = ft_i.object_id INNER JOIN
    sys.schemas AS s ON s.schema_id = o.schema_id

So silly this stuff is missing from SSMS!


问:
Jquery - fadeIn - jerky fadein
I've made a simple image switcher that fades different logos in and out. Example and full source code at http://bit.ly/ewrSgp . I fadeout the image, then queue a src attribute change, then fade back in. It seems to work smoothly for a while but after 20 seconds or so it starts to fade the image back in before changing the src, which then changes instantly and  looks ugly. Am I doing this right?

The code that runs the change is:

```<code>// fadeout old image, change to new and fadeback in.
// Call function changeimage again.
$(imToChange).fadeOut(600).queue(function (n) {
    jQuery(this).attr('src', newimageSrc);
    n();
}).fadeIn(1000, function () {
    setTimeout(function () {
        //recall image change function
        changeImage(indexToChange);
    }, o.delay);
});
</code>```

Thanks in advance.

答: Another solution: instead of changing the source of the image, how about using jQuery's .load() or .get() to replace it? Then you could use a callback function, which only fires after the loading is done, to fade it back in.

Title: Jquery - fadeIn - jerky fadein

Body:
I've made a simple image switcher that fades different logos in and out. Example and full source code at http://bit.ly/ewrSgp . I fadeout the image, then queue a src attribute change, then fade back in. It seems to work smoothly for a while but after 20 seconds or so it starts to fade the image back in before changing the src, which then changes instantly and  looks ugly. Am I doing this right?

The code that runs the change is:

// fadeout old image, change to new and fadeback in.
// Call function changeimage again.
$(imToChange).fadeOut(600).queue(function (n) {
    jQuery(this).attr('src', newimageSrc);
    n();
}).fadeIn(1000, function () {
    setTimeout(function () {
        //recall image change function
        changeImage(indexToChange);
    }, o.delay);
});

Thanks in advance.


问:
Measure distance between objects in Archilogic editor
I am using the Archilogic editor to create 3D models of building interiors.

How can I measure the distance between two objects?

答:
Unfortunately there is currently no dedicated feature within the Archilogic editor that really solves this problem.

The only workaround that you can use to receive measurement information is to either select an existing wall or place a new wall into the scene and use it as a measurement tool. You can always see the length, width and height of the selected wall in the menu on the right side.

Use a wall to get measurement information


问:
How To change the iframe url in Ionic 2 With Typescript
I have tried this but nothing worked. please help !

```<code>    var el = (<HTMLIFrameElement>document.getElementById("siteFrame"));
el.setAttribute('src',"https://www.google.co.in");
</code>```

and i had also tried this

```<code>el.src="https://www.google.co.in";
</code>```

答:
Check the Angular Docs. In your html...

```<code>[src]="https://www.google.co.in"
</code>```

No need for the getElement....

Body:
I have tried this but nothing worked. please help !

    var el = (<HTMLIFrameElement>document.getElementById("siteFrame"));
el.setAttribute('src',"https://www.google.co.in");

and i had also tried this

el.src="https://www.google.co.in";

Body:
Check the Angular Docs. In your html...

[src]="https://www.google.co.in"

No need for the getElement....


问:
String value gets converted to Time object when a model method is called using delayed job
I am using delayed job to queue a Model method in another Model like this:

article_loader.rb

```<code>date_value_in_string =  "2017-06-21 07:17:00"
Article.delay(:queue => 'article_load').article_loading([date_value_in_string])
</code>```

Even though I have passed a String as an argument to the method, inside the method it gets converted to Time object.

article.rb

```<code>def self.article_loading(args)
  date_value = args[0]
  p date_value.class # Time
end
</code>```

I don't know why this happens. Any help will be appreciated.

答:
This happens due to the fact the string looks like a datetime to Ruby's default YAML loader. DelayedJob uses YAML for serialization, so this aspect manifests.

If you want to keep the string as string, stuff some padding chars to the beginning of it, like x or something. Demo follows.

Consider this 1.yml:

```<code>ds: 2017-06-21 07:17:00
</code>```

, then, in IRB, do a:

```<code>>> require "yaml"
>> YAML.load_file("1.yml")
=> {"ds"=>2017-06-21 11:17:00 +0400}
>> _["ds"].class
=> Time
</code>```

Body:
I am using delayed job to queue a Model method in another Model like this:

article_loader.rb

date_value_in_string =  "2017-06-21 07:17:00"
Article.delay(:queue => 'article_load').article_loading([date_value_in_string])

Even though I have passed a String as an argument to the method, inside the method it gets converted to Time object.

article.rb

def self.article_loading(args)
  date_value = args[0]
  p date_value.class # Time
end

I don't know why this happens. Any help will be appreciated.

Body:
This happens due to the fact the string looks like a datetime to Ruby's default YAML loader. DelayedJob uses YAML for serialization, so this aspect manifests.

If you want to keep the string as string, stuff some padding chars to the beginning of it, like x or something. Demo follows.

Consider this 1.yml:

ds: 2017-06-21 07:17:00

, then, in IRB, do a:

>> require "yaml"
>> YAML.load_file("1.yml")
=> {"ds"=>2017-06-21 11:17:00 +0400}
>> _["ds"].class
=> Time


问:
Render VP8 Frame from webP or webM
Basically webM and webP are encoded with VP8 data. But I need only VP8 data at this moment. I tried to render VP8 data from whammy and MediaRecorder, but all ends in vain.

 So, Is there anyway to render VP8 frame from webP image in javascript ?

答:
```<code>//VP8 data from webP in Javascript

var url = canvas.toDataURL('image/webp');
url = url.slice("data:image/webp;base64,".length);
var str = atob(url); //decode the base64 encoded string
var array = new Uint8Array(str.length);
for(var i=0;i<array.length;i++)
    array[i] = str.charCodeAt(i);
var VP8_array = array.slice(20);  //Remove the header part[see ref]
</code>```

Reference : https://en.wikipedia.org/wiki/WebP

Title: Render VP8 Frame from webP or webM

Body:
//VP8 data from webP in Javascript

var url = canvas.toDataURL('image/webp');
url = url.slice("data:image/webp;base64,".length);
var str = atob(url); //decode the base64 encoded string
var array = new Uint8Array(str.length);
for(var i=0;i<array.length;i++)
    array[i] = str.charCodeAt(i);
var VP8_array = array.slice(20);  //Remove the header part[see ref]

Reference : https://en.wikipedia.org/wiki/WebP


问:
Getting a past-the-end pointer

Possible Duplicate:

  Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not?

```<code>const int n = ...;
T a[n];
T* begin = &a[0]; //or just a
T* end = begin + n;
</code>```

I know this is legal and fine. However I am wondering if the following is undefined behavior or is legal as well. Does the answer depend on type T?

```<code>T* end = &a[n];
</code>```

P.S. This question is a curiosity question, so please refrain from mentioning that vector is a better alternative to arrays and the like :)

答:
Yes.  It is undefined behavior.  No, the type of T doesn't matter.

The accepted answer in the linked duplicate is in error by its very own selection of standard citations.  Unfortunately he muddles logic at the end to come up with exactly the opposite conclusion.  The note in 3.9.2/3 is contained within a paragraph that is quite clearly talking about the type, not the ability to dereference.  The type of the pointer (array+size) is the same "as-if" there was a valid object of type T there; this does not mean that there IS a valid object there and in fact there isn't.

There is a citation in the duplicate of the C99 standard that clearly states that &array[index] will not result in a pointer dereference that is normally implied by array[index].  C99 is not C++ though and I've not seen any equivalent text that says the same thing.  It is only by that rule that it is legal in C.

C++0x will contain some of C99, I don't know if this bit is included.  You should not consider them the same language.

Most C++ compilers will happily eat it up but you could always run into a compliant compiler that does not.

Title: Getting a past-the-end pointer

Body:
Possible Duplicate:

  Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not?

const int n = ...;
T a[n];
T* begin = &a[0]; //or just a
T* end = begin + n;

I know this is legal and fine. However I am wondering if the following is undefined behavior or is legal as well. Does the answer depend on type T?

T* end = &a[n];

P.S. This question is a curiosity question, so please refrain from mentioning that vector is a better alternative to arrays and the like :)


问:
jQuery parse string before that symbols "{" "}" (different language on site)
i need to grab some text that is between that { }
But we have 3 languages same time

f.e
{:en}Resources List{:}{:ru}Список Ресурсов{:}{:uk}Список Ресурсів{:}

So if we have english version now, we need to show what is between {:en} some text {:}

答:
No need jQuery. Use regex</p>

```<code>var str = "{:en}Resources List{:}{:ru}Список Ресурсов{:}{:uk}Список Ресурсів{:}";
var regex = new RegExp("{:en}([^{]*){:}"); // english
var match = str.match(regex);
console.log(match[1]); // "Resources List"
</code>```

Body:
No need jQuery. Use regex

var str = "{:en}Resources List{:}{:ru}Список Ресурсов{:}{:uk}Список Ресурсів{:}";
var regex = new RegExp("{:en}([^{]*){:}"); // english
var match = str.match(regex);
console.log(match[1]); // "Resources List"


问:
Unsetting array elements inside a foreach loop
I have a little problem with arrays. Here is the code:

```<code>$attributes = array($_SESSION['item_01'] , $_SESSION['item_02'] , $this->item_03 , $this->item_04);
foreach($attributes as $attribute) {
    unset($attribute);
}
</code>```

This code is inside a class and $this->item_03 and item_04 is class variables.

So, it doesn't work but when I unset every array element by self (unset($_SESSION['item_01) and so on) it works.

答:
You need to unset by key, not by value.

```<code>$attributes = array($_SESSION['item_01'] , $_SESSION['item_02'] , $this->item_03 , $this->item_04);
foreach($attributes as $key => $attribute) {
    unset($attributes[$key]);

}
</code>```

if you wish to clear the session object you do:

```<code>foreach($attributes as $key => $attribute) {
    if(array_key_exists($key, $_SESSION) {
        unset($_SESSION[$key]);
        $this->{$key} = null;// this or next line
        unset($this->{$key};
    }
}
</code>```

In php it's enough to 'clear' references to items.

So if you want your memory freed, just set the values to null.

```<code>$this->item_01 = null;
$this->item_02 = null;
</code>```

then if there are no other references to it, the memory will be freed.

You need to show more of your code if you wish to have a more comprehensive answer.

Body:
I have a little problem with arrays. Here is the code:

$attributes = array($_SESSION['item_01'] , $_SESSION['item_02'] , $this->item_03 , $this->item_04);
foreach($attributes as $attribute) {
    unset($attribute);
}

This code is inside a class and $this->item_03 and item_04 is class variables.

So, it doesn't work but when I unset every array element by self (unset($_SESSION['item_01) and so on) it works.

Body:
You need to unset by key, not by value.

$attributes = array($_SESSION['item_01'] , $_SESSION['item_02'] , $this->item_03 , $this->item_04);
foreach($attributes as $key => $attribute) {
    unset($attributes[$key]);

}

if you wish to clear the session object you do:

foreach($attributes as $key => $attribute) {
    if(array_key_exists($key, $_SESSION) {
        unset($_SESSION[$key]);
        $this->{$key} = null;// this or next line
        unset($this->{$key};
    }
}

In php it's enough to 'clear' references to items.

So if you want your memory freed, just set the values to null.

$this->item_01 = null;
$this->item_02 = null;

then if there are no other references to it, the memory will be freed.

You need to show more of your code if you wish to have a more comprehensive answer.


问:
java logging : multiple small file vs one big
Using log4j on Unix, which Appender would perform the best to write 1000Meg :

1) Using RollingFileAppender writing 10 file of 100 Meg

or

2) Using a FileAppender and writing a single 1000Meg file

In other words, using java on unix, does the size matter?

Thank you

答: I think it's always preferable to use small files than large files because they are more manageable. Also, consider that with large files you may have problems in the case of file-system full because of the risk of having to remove the log file when the process is up and running to free up disk space.</p>


问:
How do I get the details of multiple missing request parameters from a Validated Spring RestController?
I'm attempting to use Spring's validation of two @RequestParams, with an @ControllerAdvice catching the exceptions thrown by the framework when a parameter is missing, and returning a 400 error with the missing parameter.

So, my code looks like:

```<code>@RestController
@Validated
public class FooController {
  @RequestMapping(value = "/foo", method = RequestMethod.GET)
  @ResponseBody
  public Foo getFoo(@RequestParam LocalDate dateFrom, @RequestParam LocalDate dateTo) {
    // Do stuff
  }
}

@ControllerAdvice
public class ExceptionController {
  @ExceptionHandler(value = {MissingServletRequestParameterException.class})
  @ResponseStatus(value = HttpStatus.BAD_REQUEST)
  @ResponseBody
  public ErrorResponse handleMissingParameterException(MissingServletRequestParameterException ex) {
    return new ErrorResponse(ex.getMessage());
  }
}
</code>```

This works perfectly if I miss a single parameter - I get a nice JSON response that looks like:

```<code>{
  "reason": "Required LocalDate parameter 'dateFrom' is not present"
}
</code>```

with a 400 status.

However if I miss both parameters, I get the same error response as above - i.e. it's only reporting the first missing parameter, where I'd prefer it if I can list all of them.

Looking at the method of the exception, it seems like it only intends to handle a single parameter - it has methods getParameterName() and getParameterType() in the singular.

Is there any way I can get Spring to report all validation errors in a single exception to improve the experience for the client?

答:
Instead introduce a one POJO filter with validate annotations

```<code>public class Filter {
    @NotNull
    private LocalDate dateFrom;
    @NotNull
    private LocalDate dateTo;
}
</code>```

and then just use it in the controller

```<code>public Foo getFoo(@Valid Filter filter) {
  // Do stuff
}
</code>```

BindingResult will provide all validation errors

Body:
I'm attempting to use Spring's validation of two @RequestParams, with an @ControllerAdvice catching the exceptions thrown by the framework when a parameter is missing, and returning a 400 error with the missing parameter.

So, my code looks like:

@RestController
@Validated
public class FooController {
  @RequestMapping(value = "/foo", method = RequestMethod.GET)
  @ResponseBody
  public Foo getFoo(@RequestParam LocalDate dateFrom, @RequestParam LocalDate dateTo) {
    // Do stuff
  }
}

@ControllerAdvice
public class ExceptionController {
  @ExceptionHandler(value = {MissingServletRequestParameterException.class})
  @ResponseStatus(value = HttpStatus.BAD_REQUEST)
  @ResponseBody
  public ErrorResponse handleMissingParameterException(MissingServletRequestParameterException ex) {
    return new ErrorResponse(ex.getMessage());
  }
}

This works perfectly if I miss a single parameter - I get a nice JSON response that looks like:

{
  "reason": "Required LocalDate parameter 'dateFrom' is not present"
}

with a 400 status.

However if I miss both parameters, I get the same error response as above - i.e. it's only reporting the first missing parameter, where I'd prefer it if I can list all of them.

Looking at the method of the exception, it seems like it only intends to handle a single parameter - it has methods getParameterName() and getParameterType() in the singular.

Is there any way I can get Spring to report all validation errors in a single exception to improve the experience for the client?

Body:
Instead introduce a one POJO filter with validate annotations

public class Filter {
    @NotNull
    private LocalDate dateFrom;
    @NotNull
    private LocalDate dateTo;
}

and then just use it in the controller

public Foo getFoo(@Valid Filter filter) {
  // Do stuff
}

BindingResult will provide all validation errors


问:
Change html  letters length on resolution change?
I have an HTML code: My Text - Loooong Text

Output: My Text - Loooong Text

When screen resolution goes to width lower than 445px, I want Loooong Text as: L. Text, and if it increases, text returns to original size.

Any help? Thanks.

答:
Here is a modification of Koby Douek's answer that might suit you.
also utilizing @media.

Wrap the collapsing portion in a span. Then use media queries to toggle its display. You can use this class to wrap anything you want to collapse.

HTML:

```<code><a>
    <span>My Text -</span>
    L<span class='collapse'>oooong</span> Text
</a>
</code>```

CSS:

```<code>@media screen and (max-width: 445px) {
   .collapse { display: none; }
   .collapse::after {content: '.'}
}
@media screen and (min-width: 446px) {
   .collapse { display: inline; }
}
</code>```

You mentioned you are generating the content using a PHP script, this strategy should be compatible.

Title: Change html <a> letters length on resolution change?

Body:
Here is a modification of Koby Douek's answer that might suit you.
also utilizing @media.

Wrap the collapsing portion in a span. Then use media queries to toggle its display. You can use this class to wrap anything you want to collapse.

HTML:

<a>
    <span>My Text -</span>
    L<span class='collapse'>oooong</span> Text
</a>

CSS:

@media screen and (max-width: 445px) {
   .collapse { display: none; }
   .collapse::after {content: '.'}
}
@media screen and (min-width: 446px) {
   .collapse { display: inline; }
}

You mentioned you are generating the content using a PHP script, this strategy should be compatible.