PHP write cache _ PHP Tutorial

Source: Internet
Author: User
Tags php write
PHP write cache. Write cache $ menu_queryexequery ($ connection, SELECTct. idastid, ct. type_name, mb. id, mb. cookname, mb. price, mb. description, mb. pinyinFROMcook_typectLEFTJOINmenubook // write cache
$ Menu_query = exequery ($ connection, "SELECT ct. id as tid, ct. type_name, mb. id, mb. cookname,
Mb. price, mb. description, mb. pinyin FROM cook_type ct left join menubook mb ON ct. id = mb. cook_type WHERE
Mb. id = ". $ cook_id );
$ Menu_result = mysql_fetch_array ($ menu_query );

// Echo "menu id:". $ cook_id. "; Category id:". $ menu_result [tid]; exit;
// This menu
$ Row [mid] = $ cook_id;
$ Row [menu_name] = $ cook_name;
$ Row [description] = $ description;
$ Row [menu_price] = $ cook_price;
$ Row [pinyin] = ChangeToPinyin (iconv ("UTF-8", "gb2312", $ cook_name), 1 );

If (file_exists ("./menubook. php "))
{
Require_once ("./menubook. php ");
}


If (is_array ($ menu_cache )&&! Empty ($ menu_cache ))
{
$ Classnum = count ($ menu_cache );
$ Unmatchnum = 0;
For ($ I = 0; $ I <$ classnum; $ I ++)
{
If ($ menu_result [tid]! = $ Menu_cache [$ I] [tid])
{
$ Unmatchnum ++;
Continue;
}
Else // locate the category and continue searching for whether the cache of the course exists
{
$ Cartenum = count ($ menu_cache [$ I] [list]);
$ Unmarrynum = 0;
For ($ j = 0; $ j <$ cartenum; $ j ++)
{
If ($ menu_cache [$ I] [list] [$ j] [mid]! = $ Cook_id)
{
$ Unmarrynum ++;
Continue;
}
Else // modify the menu
{
$ Menu_cache [$ I] [list] [$ j] [menu_name] = $ cook_name;
$ Menu_cache [$ I] [list] [$ j] [description] = $ description;
$ Menu_cache [$ I] [list] [$ j] [menu_price] = $ cook_price;
$ Menu_cache [$ I] [list] [$ j] [pinyin] = $ row [pinyin];
}
}

// Newly added menu
If ($ cartenum = $ unmarrynum)
{
$ Menu_cache [$ I] [list] [] = $ row;
}
}
}

// Category not found
If ($ unmatchnum = $ classnum)
{
$ Type_row [tid] = $ menu_result [tid];
$ Type_row [type_name] = $ menu_result [type_name];
$ Type_row [list] [0] = $ row;

$ Menu_cache [] = $ type_row;

}
}
Else {// array generation
$ Type_row [tid] = $ menu_result [tid];
$ Type_row [type_name] = $ menu_result [type_name];
$ Type_row [list] [0] = $ row;

$ Menu_cache [] = $ type_row;

}
// Print_r ($ menu_cache );
// Write a file
Ob_start ();
Var_export ($ menu_cache );
$ Content = ob_get_contents ();
Ob_end_clean ();

$ Filename = "menubook. php ";
$ Fp = fopen ($ filename, "w ");
Fwrite ($ fp ," ");
Fclose ($ fp );

2. add menu and write to cache

$ Str = ChangeToPinyin (iconv ("UTF-8", "gb2312", $ cook_name), 1 );
$ Query_cook_add = "insert into menubook (cookname, price, cook_type, description, pinyin) values (". $ cook_name. ",". $ cook_price. ",". $ cook_type. ",". $ description. ",". $ str. ")";
$ Cursor_cook_add = exequery ($ connection, $ query_cook_add );
$ Cook_id = mysql_insert_id ();

$ Menutype_query = exequery ($ connection, "SELECT type_name FROM cook_type WHERE id =". $ cook_type );
$ Menutype_result = mysql_fetch_array ($ menutype_query );


// This menu
$ Row [mid] = $ cook_id;
$ Row [menu_name] = $ cook_name;
$ Row [description] = $ description;
$ Row [menu_price] = $ cook_price;
$ Row [pinyin] = $ str;

If (file_exists ("./menubook. php "))
{
Require_once ("./menubook. php ");
}

If (is_array ($ menu_cache )&&! Empty ($ menu_cache ))
{
$ Classnum = count ($ menu_cache );
$ Unmatchnum = 0;
For ($ I = 0; $ I <$ classnum; $ I ++)
{
If ($ cook_type! = $ Menu_cache [$ I] [tid])
{
$ Unmatchnum ++;
Continue;
}
Else // locate the category and add and modify the cache of the product dishes
{
$ Menu_cache [$ I] [list] [] = $ row;
}

}
If ($ classnum = $ unmatchnum) // no category is found
{
$ Type_row [tid] = $ cook_type;
$ Type_row [type_name] = $ menutype_result [type_name];
$ Type_row [list] [0] = $ row;

$ Menu_cache [] = $ type_row;

}
}

Else {// array generation
$ Type_row [tid] = $ cook_type;
$ Type_row [type_name] = $ menutype_result [type_name];
$ Type_row [list] [0] = $ row;

$ Menu_c

Explain $ menu_query = exequery ($ connection, SELECT ct. id as tid, ct. type_name, mb. id, mb. cookname, mb. price, mb. description, mb. pinyin FROM cook_type ct left join menubook...

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.