drf - 排序组件OrderingFilter分析总结

排序组件OrderingFilter

models.py 文件
from django.db import models
class BaseModel(models.Model):
    is_delete = models.BooleanField(default=False)
    create_time = models.DateTimeField(auto_now_add=True)
    class Meta:
        abstract = True
        
class Car(BaseModel):
    name = models.CharField(max_length=32)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    brand = models.ForeignKey('Brand', db_constraint=False, on_delete=models.DO_NOTHING, related_name='cars')
    @property
    def brand_name(self):
        return self.brand.name
    class Meta:
        db_table = 'old_boy_car'
        verbose_name = '汽车'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


class Brand(BaseModel):
    name = models.CharField(max_length=32)
    class Meta:
        db_table = 'old_boy_brand'
        verbose_name = '品牌'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name
serializer.py文件
from rest_framework.serializers import ModelSerializer
from . import models
class CarModelSerializer(ModelSerializer):
    class Meta:
        model = models.Car
        fields = ('name','price','brand','brand_name')
        extra_kwargs = {
            "brand":{
                'write_only':True
            },
            'brand_name':{
                'read_only':True
            },
        }
views.py 文件
from rest_framework.viewsets import ModelViewSet
from . import models, serializer
from rest_framework.filters import OrderingFilter

class CarModelViewSet(ModelViewSet):
    queryset = models.Car.objects.filter(is_delete=False)
    serializer_class = serializer.CarModelSerializer
    filter_backends = [OrderingFilter]
    # ordering_fields = ['pk','-price']
    # ordering_fields = '__all__'

总结

# 如果有ordering_fields
    # url输入的是该字段,就按该字段排序(ordering_fields必须是可以参与order_by()的字段,否则会报错)否则不排序
    
# 如果ordering_fields = '__all__':
    # 1. 如 url:/ordering = -sdfsfd,则 ordering = None,不排序
    # 2. 如 url:/ordering = -price, 则 ordering = -price,按-price排序
    
# 如果没有指定ordering_fields,
    # 1. 不参与序列化,如:sdsadf。则 ordering = None,不排序
    # 2. 参与序列化且是表字段,如:price,则 ordering = price, 按price排序,
    # 3. 参与序列化不是表字段,如:brand_name, 则 ordering = brand_name,报错(order_by(brand_name)出错)

转载于:https://www.cnblogs.com/863652104kai/p/11514666.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Appendix CWriting Your Own Functions. . . . . . . . . . . . . . . . . . 487 The Structure of Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488 Returning Values from Functions. . . . . . . . . . . . . . . . . . . . . . . 488 Using Functions in Your Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 Using include() and require(). . . . . . . . . . . . . . . . . . . . . . . . . . . 492 Appendix DWriting Your Own Classes and Objects. . . . . . . . . . 495 Working with Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496 Creating an Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 Object Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 Namespaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502 Appendix EDatabase Normalization and SQL Reference. . . . . . 505 Understanding Database Normalization. . . . . . . . . . . . . . . . . . . . 506 Applying the Normal Forms. . . . . . . . . . . . . . . . . . . . . . . . . . . 506 Normalizing the my_contacts Table. . . . . . . . . . . . . . . . . . . . . 510 Other Normal Forms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513 Basic MySQL Reference. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513 Creating or Dropping a Database. . . . . . . . . . . . . . . . . . . . . . 514 Creating or Dropping a Table. . . . . . . . . . . . . . . . . . . . . . . . . . 514 Altering a Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515 Inserting, Updating, or Replacing Within a Table. . . . . . . . . . . 515 Deleting from a Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517 Selecting from a Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517 Grouping, Ordering, and Selecting Unique Values. . . . . . . . . 520 Using the SHOW Command. . . . . . . . . . . . . . . . . . . . . . . . . . . 521 Appendix FUsing SQLite. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 Examples of SQLite in Action. . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 Creating a Table and Storing Data with SQLite. . . . . . . . . . . . 525 Retrieving Items with SQLite. . . . . . . . . . . . . . . . . . . . . . . . . . 526 Performing Other Tasks with SQLite. . . . . . . . . . . . . . . . . . . . 528 xvii CONTENTS Appendix GGetting Help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 PHP Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 Web Sites. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 Mailing Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 User Groups. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 MySQL Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 Apache Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix PART I GETTING STARTED. . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1 Installing and Configuring MySQL. . . . . . . . . . . . . . . . 3 Various MySQL Distributions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Installing MySQL on Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Testing Your MySQL Installation. . . . . . . . . . . . . . . . . . . . . . . . . 12 Installing MySQL for Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Testing Your MySQL Installation. . . . . . . . . . . . . . . . . . . . . . . . . 20 Chapter 2 Installing Apache. . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Installing Apache for Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Configuring Apache on Windows. . . . . . . . . . . . . . . . . . . . . . . . 29 Starting and Connecting to Apache. . . . . . . . . . . . . . . . . . . . . . 31 Installing Apache for Linux/UNIX. . . . . . . . . . . . . . . . . . . . . . . . . . 32 Configuring Apache on Linux/UNIX. . . . . . . . . . . . . . . . . . . . . . 34 Starting and Connecting to Apache. . . . . . . . . . . . . . . . . . . . . . 36 Chapter 3 Installing PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Installing PHP for Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Configuring Apache to Use PHP. . . . . . . . . . . . . . . . . . . . . . . . . 41 Testing the PHP Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Installing PHP for Linux/UNIX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Configuring Apache to Use PHP. . . . . . . . . . . . . . . . . . . . . . . . . 46 Testing the PHP Installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 PART II THE ABSOLUTE BASICS OF CODING IN PHP. . . . 49 Chapter 4 Mixing PHP and HTML. . . . . . . . . . . . . . . . . . . . . . . . 51 How PHP Is Parsed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 PHP Start and End Tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Code Cohabitation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 The Importance of the Instruction Terminator. . . . . . . . . . . . . . 57 Escaping Your Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Commenting Your Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Chapter 5 Introducing Variables and Operators. . . . . . . . . . . . 65 What’s a Variable?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Naming Your Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 PHP Variable and Value Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 What’s an Operator?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Assignment Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Arithmetic Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Comparison Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Logical Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 viii CONTENTS Chapter 6 Using PHP Variables. . . . . . . . . . . . . . . . . . . . . . . . . 85 Getting Variables from Forms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Creating a Calculation Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Creating the Calculation Script. . . . . . . . . . . . . . . . . . . . . . . . . . 89 Submitting Your Form and Getting Results. . . . . . . . . . . . . . . . 91 HTTP Environment Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Retrieving and Using REMOTE_ADDR. . . . . . . . . . . . . . . . . . . . 93 Retrieving and Using HTTP_USER_AGENT. . . . . . . . . . . . . . . . 95 PART III START WITH THE SIMPLE STUFF. . . . . . . . . . . . . . 97 Chapter 7 Displaying Dynamic Content. . . . . . . . . . . . . . . . . . . 99 Displaying Browser-Specific HTML. . . . . . . . . . . . . . . . . . . . . . . . 100 Displaying Platform-Specific HTML. . . . . . . . . . . . . . . . . . . . . . . . 103 Working with String Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Creating an Input Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Creating a Script to Display Form Values. . . . . . . . . . . . . . . . . 109 Submitting Your Form and Getting Results. . . . . . . . . . . . . . . 111 Redirecting to a New Location. . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Creating a Redirection Form. . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Creating the Redirection Script and Testing It. . . . . . . . . . . . . 115 Chapter 8 Sending E-Mail. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Using an SMTP Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 SMTP-Related Changes in php.ini. . . . . . . . . . . . . . . . . . . . . . 119 A Simple Feedback Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Creating the Feedback Form. . . . . . . . . . . . . . . . . . . . . . . . . . 120 Creating a Script to Mail Your Form. . . . . . . . . . . . . . . . . . . . . 122 Submitting Your Form and Getting Results. . . . . . . . . . . . . . . 125 ix CONTENTS A Feedback Form with Custom Error Messages. . . . . . . . . . . . . 127 Creating the Initial Script. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Adding Error Checking to the Script. . . . . . . . . . . . . . . . . . . . 129 Submitting Your Form and Getting Results. . . . . . . . . . . . . . . 134 Saving the Values if You Make an Error. . . . . . . . . . . . . . . . . . 136 Chapter 9 Using Your File System. . . . . . . . . . . . . . . . . . . . . . 139 File Paths and Permissions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Displaying Directory Contents. . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Working with fopen() and fclose(). . . . . . . . . . . . . . . . . . . . . . . . . 143 Creating a New File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Appending Data to a File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Reading Data from a File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Sending File Contents via E-Mail. . . . . . . . . . . . . . . . . . . . . . . 155 File System Housekeeping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Copying Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Renaming Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Deleting Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Chapter 10Uploading Files to Your Web Site. . . . . . . . . . . . . . 165 Checking Your php.ini File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Understanding the Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Creating the Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Creating the Upload Script. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Uploading a File Using Your Form and Script. . . . . . . . . . . . . . . . 172 x CONTENTS PART IV GETTING TO KNOW YOUR MYSQL DATABASE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Chapter 11Establishing a Connection and Poking Around. . . . 177 Working with User Privileges in MySQL. . . . . . . . . . . . . . . . . . . . 178 Creating a New User. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Connecting to MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Breaking Your Connection Script. . . . . . . . . . . . . . . . . . . . . . . 182 Listing Databases on a Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Listing Tables in a Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Creating a New Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Deleting a Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Chapter 12Creating a Database Table. . . . . . . . . . . . . . . . . . . . 197 Planning for Your Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Basic MySQL Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Defining Your Fields. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 The Importance of Unique Fields. . . . . . . . . . . . . . . . . . . . . . . 201 A Two-Step Form Sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 Step 1: Number of Fields. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 Step 2: Defining Your Fields. . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Starting the Table Creation Process. . . . . . . . . . . . . . . . . . . . . 208 Creating the Table-Creation Script. . . . . . . . . . . . . . . . . . . . . . . . 210 Create That Table!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 Chapter 13Inserting Data into the Table. . . . . . . . . . . . . . . . . . 217 Creating the Record Addition Form. . . . . . . . . . . . . . . . . . . . . . . 218 Creating the Record Addition Script. . . . . . . . . . . . . . . . . . . . . . . 222 Populating Your Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 xi CONTENTS Chapter 14Selecting and Displaying Data. . . . . . . . . . . . . . . . . 231 Planning and Creating Your Administrative Menu. . . . . . . . . . . . 232 Selecting Data from the my_music Table. . . . . . . . . . . . . . . . . . . 233 Displaying Records Ordered by ID. . . . . . . . . . . . . . . . . . . . . . 234 Displaying Records Ordered by Date Acquired. . . . . . . . . . . . 237 Displaying Records Ordered by Title. . . . . . . . . . . . . . . . . . . . 238 Displaying Records Ordered by Artist. . . . . . . . . . . . . . . . . . . 240 Displaying Records Ordered by Multiple Criteria. . . . . . . . . . 243 PART V USER AUTHENTICATION AND TRACKING. . . . . 245 Chapter 15Database-Driven User Authentication. . . . . . . . . . . 247 Why Authenticate Anyone?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 Creating the User Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 Adding Users to Your Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Creating the User Addition Form and Script. . . . . . . . . . . . . . 250 Adding Some Users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Creating the Login Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Creating the Authentication Script. . . . . . . . . . . . . . . . . . . . . . . . 258 Trying to Authenticate Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Chapter 16Using Cookies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 What Are Cookies?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 Setting Cookies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 Counting Time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 Setting a Test Cookie. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 Using Cookie Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 Using Cookies with Authentication. . . . . . . . . . . . . . . . . . . . . 269 xii CONTENTS Chapter 17Session Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Before You Begin…Checking php.ini. . . . . . . . . . . . . . . . . . . . . . 278 What’s a Session?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Understanding Session Variables. . . . . . . . . . . . . . . . . . . . . . . . . 279 Starting a Session. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Registering and Modifying Session Variables. . . . . . . . . . . . . . 282 Managing User Preferences with Sessions. . . . . . . . . . . . . . . . . . 284 Starting a Session and Registering Defaults. . . . . . . . . . . . . . . 284 Making Preference Changes. . . . . . . . . . . . . . . . . . . . . . . . . . . 288 Displaying Changes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 PART VI CREATING YOUR OWN CONTACT MANAGEMENT SYSTEM. . . . . . . . . . . . . . . . . . . 293 Chapter 18Planning Your System. . . . . . . . . . . . . . . . . . . . . . . 295 Planning and Creating the Administration Menu. . . . . . . . . . . . . 296 Logging In to the Administration Menu. . . . . . . . . . . . . . . . . . 301 Defining the my_contacts Table. . . . . . . . . . . . . . . . . . . . . . . . . . 303 Modifying the Table-Creation Scripts. . . . . . . . . . . . . . . . . . . . 304 Creating the my_contacts Table. . . . . . . . . . . . . . . . . . . . . . . . 309 Chapter 19Adding Contacts. . . . . . . . . . . . . . . . . . . . . . . . . . . 313 Creating the Record-Addition Form. . . . . . . . . . . . . . . . . . . . . . . 314 Creating the Record-Addition Script. . . . . . . . . . . . . . . . . . . . . . 319 Populating Your Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 Chapter 20Modifying Contacts. . . . . . . . . . . . . . . . . . . . . . . . . 327 Creating the Record-Selection Form. . . . . . . . . . . . . . . . . . . . . . 328 Creating the Record-Modification Form. . . . . . . . . . . . . . . . . . . . 333 Creating the Record-Modification Script. . . . . . . . . . . . . . . . . . . 338 Modifying Contacts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 xiii CONTENTS Chapter 21Deleting Contacts. . . . . . . . . . . . . . . . . . . . . . . . . . 345 Using the Record-Selection Form. . . . . . . . . . . . . . . . . . . . . . . . . 346 Creating the Record-Deletion Form. . . . . . . . . . . . . . . . . . . . . . . 351 Creating the Record-Deletion Script. . . . . . . . . . . . . . . . . . . . . . . 355 Deleting Contacts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 Chapter 22Working with Contacts. . . . . . . . . . . . . . . . . . . . . . 361 Modifying Your Administrative Menu. . . . . . . . . . . . . . . . . . . . . . 362 Showing the Number of Contacts. . . . . . . . . . . . . . . . . . . . . . 362 Displaying Today’s Date. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 Showing the Birthdays in the Current Month. . . . . . . . . . . . . . 372 Selecting Data from the my_contacts Table. . . . . . . . . . . . . . . . . 379 Displaying the Record List. . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 Displaying Read-Only Records. . . . . . . . . . . . . . . . . . . . . . . . . 383 PART VII ADDITIONAL PROJECT EXAMPLES. . . . . . . . . . . 391 Chapter 23Managing a Simple Mailing List. . . . . . . . . . . . . . . . 393 A Brief Word About Mailing List Software. . . . . . . . . . . . . . . . . . 394 Developing a Subscription Mechanism. . . . . . . . . . . . . . . . . . . . . 394 Creating the subscribers Table. . . . . . . . . . . . . . . . . . . . . . . . . 394 Creating the Subscription Form. . . . . . . . . . . . . . . . . . . . . . . . 396 Testing the Subscription Form. . . . . . . . . . . . . . . . . . . . . . . . . 403 Developing the Mailing Mechanism. . . . . . . . . . . . . . . . . . . . . . . 406 Creating the Newsletter Form. . . . . . . . . . . . . . . . . . . . . . . . . 406 Creating the Script to Mail Your Newsletter. . . . . . . . . . . . . . 407 Testing Your Mailing List Mechanism. . . . . . . . . . . . . . . . . . . . 410 Troubleshooting Your Mailing List Mechanism. . . . . . . . . . . . . 411 xiv CONTENTS Chapter 24Creating Custom Logs and Reports. . . . . . . . . . . . . 413 A Note About Apache Log Files. . . . . . . . . . . . . . . . . . . . . . . . . . 414 Simple Access Counting with MySQL. . . . . . . . . . . . . . . . . . . . . . 415 Creating the Database Table. . . . . . . . . . . . . . . . . . . . . . . . . . 415 Creating the Code Snippet. . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 Displaying the Count. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 Creating Your Personal Access Report. . . . . . . . . . . . . . . . . . . 422 Chapter 25Working with XML. . . . . . . . . . . . . . . . . . . . . . . . . . 433 What Is XML?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 Basic XML Document Structure. . . . . . . . . . . . . . . . . . . . . . . . 434 Preparing to Use XML with PHP. . . . . . . . . . . . . . . . . . . . . . . . . . 437 Parsing XML with PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438 Parse and Display Content from XML Files. . . . . . . . . . . . . . . 439 PART VIII APPENDIXES. . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 Appendix AAdditional Configuration Options. . . . . . . . . . . . . . 445 Windows Extensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 Linux Configuration Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448 Appendix BBasic PHP Language Reference. . . . . . . . . . . . . . . . 451 PHP Start and End Tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Floats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 Integers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 Variables from HTML Forms. . . . . . . . . . . . . . . . . . . . . . . . . . . 454 Variables from Cookies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 Environment Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 xv CONTENTS Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 Arithmetic Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 Assignment Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 Comparison Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 Increment/Decrement Operators. . . . . . . . . . . . . . . . . . . . . . . 457 Logical Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 Control Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458 if...else if...else. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459 while. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460 for. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460 foreach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Built-In Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Array Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Database Connectivity Functions for MySQL. . . . . . . . . . . . . . 465 Date and Time Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 File System Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468 HTTP Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472 mail() Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473 Mathematical Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474 Miscellaneous Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476 Program Execution Functions. . . . . . . . . . . . . . . . . . . . . . . . . . 478 Regular Expression Functions. . . . . . . . . . . . . . . . . . . . . . . . . . 479 Session-Handling Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . 480 String Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 Variable Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 Other Changes for PHP 6.0. . . . . . . . . . . . . . . . . . . . . . . . . . . 486 xvi CONTENTS

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值