PHP7-MySQLi在分页中的应用

获取页码,设置每页行数

$page = $_POST["page"];
if($page == ""||$page <= 0){
    $page = 1;
}
$pageSize = 15;

打开MySQL数据库

$mysqli = new mysqli($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);

执行SQL语句

$result = $mysqli->query("select 1 from record_visitor");

获取数据总行数

$rowCount = $result->num_rows;
//$rowCount = $result->num_rows是mysqli面向对象风格,等同于$rowCount = mysqli_num_rows($result);

获取数据总页数

$pageNum = ceil($rowCount / $pageSize);
if($page > $pageNum){
    $page = 1;
}

获取数据的偏移量

$offset = ($page - 1) * $pageSize;
//获取的数据从$offset+1开始,例:$page=0,$offset=0,从第1个数据向后推移;$page=2,$offset=5,从第6个数据向后推移.

获取当前页的数据

$result = $mysqli->query("select ip,referer,href from visitor order by time desc limit $offset,$pageSize");
//从$offset+1个数据开始展现$pageSize个数据,例:数据1-10,$page=0,$offset=0,$pageSize=5,展现:6,7,8,9,10.

展现数据

while ($row = $result->fetch_assoc()) {
    echo $row["ip"];
    echo $row["referer"];
    echo $row["href"];
}
//$row = $result->fetch_assoc()是mysqli面向对象风格,等同于$row = mysqli_fetch_assoc($result);循环输出每行数据.

What does it feel like to survive death?

I survived death three times during a 23 day period.

I was 14 at the time, located in Pennsylvania, USA. I had come back from a trip to India. I went during the monsoon season, July 2006. I came home in middle of August, I was to start school in about 2 weeks.

School started, I had bought all my back to school clothes, pens, notebooks, pencils, etc. Suddenly, during history class I get a severe headache, it wasn’t like your normal temple headache. It was more like the headache formed a halo on my head. It started from the forehead all the way around in a circle. I went to the nurse and took some Tylenol. The nurse called my parents and let me go home early.

I went home and I fell asleep. I woke up after maybe 3 hours with a very high fever reached 102 degrees. My parents made an appointment with my pediatrician and he said that it might just be because of the season changing. He advised me to take Motrin every 4 – 6 hours for the fever. I went home and started getting the shakes, I would be feeling extremely hot for an hour or two, and extremely cold the next couple of hours.

My parents rushed me to the emergency room where they did an MRI, CT Scan, Blood and Urine work which all came back negative. As a final resort, they did a Lumbar Puncture (Spinal Tap). The doctor who was performing the procedure was a resident, there was no senior doctor present. He poke the needle in between my vertebrae approximately 4-5 times, when he gave up and called his senior. His senior doctor withdrew Cerebral Spinal Fluid (CSF) and sent it off for testing.

During that time, my mom told the doctor that I have all the symptoms of malaria and that I had visited India during the rainy season. The doctor agreed and said that it does look like malaria, but since they didn’t have any proof; it would be unlawful for them to provide me any medication that may cause harm to me. The CSF checked out to be negative. I was sent home with Tylenol.

Once I reached home, I slept for maybe 4-5 hours. Once I woke up, I was burning in a fever and was hallucinating. I kept yelling at my parents to stay away from me because I thought they were going to hit me on the head with a remote control. I fell asleep after 5 minutes of hallucinating. After waking up, I was totally normal and got up to go to the bathroom. As soon as I stood up, I started to walk as if I was drunk. I was not coordinated. I got to the bathroom but could not urinate.

I was rushed to the ER again, where they inserted a tube through my urethra to remove the urine from the bladder. I was transferred via ambulance to Hershey Medical Center. I was sent to get more testing done like an MRI which showed something in my neck, they assumed. During that time, I was having very small seizures which I was not treated for.

I was taken in for another LP, which resulted in me having a major seizure, respiratory and cardiac arrest. They declared me dead on the spot. They still paged CODE BLUE and called all the ICU doctors in the room to perform CPR.

My mom was in my room speaking to a social worker when my nurse came running to her and screamed, “If you want to see your daughter for the last time, you better come with me”!

My mom is a healthy woman and she never runs, she just can’t. My mom, dad, aunty and uncle ran like anything, they threw their phones away and literally pushed people to get to the testing room.

There, I was laying bra-less and top-less on the examination table where they were giving me electric shock to my heart.

The resident who performed the LP came out and faced my mom. My mom grabbed her shoulders and shook her violently and screamed, “WHAT HAVE YOU DONE WITH MY DAUGHTER YOU BLOODY PAKISTANI! YOU’RE TAKING REVENGE BECAUSE WE ARE INDIAN AND YOU ARE PAKISTANI!! HOW DARE YOU”!!!

Every doctor there, utterly shocked. My dad took her to the side and made her calm down. Fiza, the resident who performed the LP, was crying and said, “Mrs. Modi, I didn’t do anything to your daughter. She was laughing and talking about her life, school, and you. We don’t know what happened.. We weren’t prepared for this”. My mom looked at her with furious eyes.

After 3 electric shocks, and 7 minutes without oxygen, they revitalized my heart but could not get my breathing back. I was unconscious and had a breathing tube stuck down my throat, IVs in both of my hands, heart monitors hooked up, and a blood pressure cuff on. I was transferred into the PICU (Pediatric Intensive Care Unit). I came into consciousness that night and recognized everyone. I shook my head if I knew someone or not.

The next day, I was taken again for another LP, which resulted in my going into a coma for 23 days. The doctors said that there were uncountable white blood cells in my CSF, which meant a viral infection.

During the third day of the coma, my body temperature went below 90 degrees, it was sudden and there was no reason for this to happen. The nurses piled heated blankets on me and surrounded me with heated lamps. I was left like that for about an hour. The doctor called it serious and said if my body temperature didn’t go above 90 degrees, I could die. After one hour, they removed the lamps and blankets, my body temperature rose immediately.

A couple days later, I lost a lot of blood resulting in my hemoglobin going down below 5 (the normal is 11.5-15 for women). They didn’t know where the blood loss was from.. So they gave me 3 units of blood and again called it fatal. Finally, after the blood transfusion, my hemoglobin came up to a safe level.

The date was now September 19, 2006. A family doctor of ours is an Infectious Disease Specialist. He spoke to the team of doctors that were in charge, and requested them to give me a 14 day course of Doxycycline and Quinine because I didn’t have anything they were treating me for. I had malaria.

The doctors didn’t approve of my doctors’ request so my mom laid down by their feet. In a position where her face was facing the ground and her head was touching the tip of their shoes. She cried and requested them to listen to our family doctor.

Finally, at 4am the doctors injected me with the first dosage of those medicines. My parents went to sleep.

On September 21, 2006. The doctors decided to take me off of life support and told my parents to call all of my family. My mom begged them and told them to keep me on life support until September 29 because it’s my birthday. The doctors said that if there was no improvement after the 29th, they would pull the plug from my breathing machine which would lead to death.

On September 29, 2006, my mom catered for 60+ people, decorated my room in the PICU and called all my family. At 3:05 pm, the exact time I was born, everyone was signing Happy Birthday and my dad held my hand and cut the cake. I opened my eyes and was staring up at the ceiling, I couldn’t recognize anyone.

My family screamed for the doctor, he came in and gave me a quick check up and screamed and jumped himself. He hugged my mom with teary eyes and said, “Mom, you saved us from committing an unforgivable sin! God bless your spirit. Your daughter will survive”! I went into a coma again after 10-20 minutes.

On October 5th, 2006, I was sent into the operating room to transfer the breathing tube from my mouth, to my directly through my neck and vocal cords. After the anesthesia wearing off, I came out of my coma and started to recognize everyone.

But the coincidence is that, when my mother was pregnant, her original due date was October 5, 1991. Another thing, everyone in my family except my mom knew I wasn’t going to make it.. Her faith and belief is what saved me. I was paralyzed from my neck down, it’s been 8 years just yesterday (09/29/13) and I am able to move and contract a few leg muscles which the doctors thought I would never be able to do.

I’ve posted my story many times as answers for different questions, but never in so much detail. I’m sorry if you are being forced to read this the umpteenth time but I love to share this story to give inspiration and motivation to others who are having a hard time.

NOTHING IS IMPOSSIBLE. 🙂
Stay smiling! And thanks for reading!

Link

ASP-DateAdd时间增加

ASP内置函数DateAdd(interval, number, date)

1、interval标识你要加的日期部分,具体参数如下:
yyyy → 年
m → 月
d → 日
h → 小时
n → 分钟
s → 秒

2、number是你要加的数字,代表秒、分、天等。

3、date是日期,可以是任意时间,若是现在便是now()。

如需增加一年,则:DateAdd(“yyyy”,1,”2017-04-11 00:00:00″)
同样,如需在当前日期的基础上增加一月,则:DateAdd(“m”,1,now())

jQuery-PHP跨域请求数据

jQuery:

 1 //获取域名
 2 function getDomain(url){
 3     var a = document.createElement('a');
 4     a.href = url;
 5     url=a.hostname;
 6     return url;
 7 }
 8 
 9 //记录访客
10 function recordVisitor(){
11     var referrerMz = escape(getDomain(document.referrer));
12     var hrefMz = escape(getDomain(window.location.href));
13     sendInfo="judgeMz=413322&referrerMz="+escape(referrerMz)+"&hrefMz="+escape(hrefMz);
14     $.ajax({ 
15         type: "get", 
16         async: true, 
17         url: "http://www.mazey.net/config/api/record-receive.php", 
18         data:{judgeMz:413322,referrerMz:referrerMz,hrefMz:hrefMz}, 
19         dataType: "jsonp", 
20         jsonp: "callback",
21         jsonpCallback:"returnFun",
22         success: function(data){ 
23             myArr=data.split("-|-")
24             if("0507"==myArr[0]){
25                 console.log(myArr[1]);
26             }else if("0215"==myArr[0]){
27                 console.log(myArr[1]);
28             }
29         }, 
30         error: function(){ 
31             console.log("Server Error!");
32         } 
33     });
34 }
35 
36 //加载
37 $(document).ready(function () { 
38     recordVisitor();
39 });

PHP:

 1 <?php
 2 require '../config.php';
 3 $judgeMz=$_GET["judgeMz"];//TODO 后续做一个验证不是413322的报错
 4 $referrerMz=$_GET["referrerMz"];
 5 $hrefMz=$_GET["hrefMz"];
 6 $visitorIP=getIP();
 7 
 8 $data = returnFun($referrerMz,$hrefMz,$visitorIP); 
 9 exit($_GET['callback'] . '(' . json_encode($data) . ')'); 
10 
11 function returnFun($referrerMz,$hrefMz,$visitorIP) { 
12     $urlRecordVisitor='http://www.mazey.cn/config/config-asp/api/record-receive.asp?referrerMz='.$referrerMz.'&hrefMz='.$hrefMz.'&visitorIP='.$visitorIP;
13     $resultMz = file_get_contents($urlRecordVisitor);
14     return $resultMz;
15 }
16 ?>

其他:

因为http://www.mazey.cn/config/config-asp/api/record-receive.asp在国内,所以访问起来好像有点慢。准备按照asp重写下php的后端写入代码,本来计划了不少事情,其他事情这一步做完以后再说吧。