Learn about query statements from a MySQL example

Source: Internet
Author: User
Since school so many years, have come to learn from an example is the fastest and most effective, and can cultivate a strong practical ability, which is a very
A good way to learn. Try not to visit. For example, when you look at a book, start with the examples from each chapter, and find out what you don't know and what you don't know or new knowledge.
And then targeted learning. Take a look at the following example:
<?php
$ip = getenv ("REMOTE_ADDR");
echo "$ip";
$conn =mysql_connect (' ip ', ' root ', ' * * * ');
mysql_select_db (' db ', $conn);
$sql = "Select *from counter where ip=" $ip ";";
$result =mysql_query ($sql, $conn);
$num =mysql_num_rows ($result);
$count =mysql_query ("Select*from counter", $conn);
$count =mysql_num_rows ($count);
echo "$num";
echo "$count";
if ($num ==0)
{
$sum = 1;
$count;
$sql = "INSERT INTO counter (ip,sum,countdata) VALUES (' $ip ', ' 1 ', ' $count ')";
mysql_query ($sql, $conn);
Mysql_close ($conn);
echo "$count";
}
Else
{
$my = "Select sum from counter where ip= ' $ip '";
$BBBBBB =mysql_query ($my) or Die (Mysql_error ());
$row =mysql_fetch_array ($BBBBBB);
@ $sum = $row [sum];
echo "$sum";
$sum;
$sql = "Update counter set sum= ' $sum ' where ip= ' $ip '";
mysql_query ($sql);
Mysql_close ($conn);
}
$str _count=strval ($count);
$str _count=chop ($str _count);
$count _len=strlen ($str _count);
$image _count= "";
if ($count _len<6)
{for ($j =0; $j <6-$count _len; $j)
{$image _count= $image _count. " ;
}
}
for ($i =0; $i < $count _len; $i)
{
$nom =substr ($str _count, $i, 1);
$image _count = $image _count. " $image _count = $image _count. $nom;
$image _count = $image _count. ". GIF ' > ';
}
echo "$image _count<br>";
Print "This is your first". $sum. " Visits ";
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.