开发者

MySQL table VS PHP Array's

I have an application that create child's gifts applications, and every application owner can add own gifts, right now i'm storing gifts in a php array :

<?php
$gifts_array = array(
array(>4,"Flower",>250,"5_250.jpg",301),
array(1,"a Good Day",30,"3_30.jpg",153),
array(2,"cat",10,"3_10.gif",139),
array(3,"batman",20,"2_20.jpg",101),
array(11,"White Wolf",100,"11_100.jpg",5),
array(10,"crazy cat",30,"10_30.gif",2),
array(8,"Gift",100,"6_100.jpg",2),
array(12,"Car",120,"12_120.jpg",1),
array(9,"cat 2",30,"9_30.gif",1),
array(7,"2Pac",500,"3_500.jpg",0),
array(6,"Outlawz",开发者_运维问答500,"4_500.jpg",0)
);
?>

I need to update gift counter every time sent, so i have to do a loop to find the gift then increment and write the whole array in the file.

It is good to create this Array like that :

    '100'=>array('gname'=>"Flower",'gpoints'=>250,'gpic'=>"5_250.jpg",'gviews'=>301),
     100 is the Gift ID.

What is the best solution : - Create for every application a MySQL table ? - Use one Table for all applications ? - Use one MySQL table to store all apps gifts and cache MySQL results for each application after Gift INSERT/UPDATE/DELETE ?


Just create one table with the same number of columns, plus one identifying which "application" it corresponds to. Don't create a new identical table for each app, and don't keep reading/writing from a text file, both are concurrency and maintenance nightmares.


Use a single table

//Create a table to hold all your info
CREATE applications (id INTEGER AUTO INCREMENT, gname VARCHAR(255), gpoints INTEGER, gpic VARCHAR(255), gviews INTEGER);

//Increment the number of views
UPDATE applications SET gviews=gviews+1 WHERE gname='Flower'

//Get the names of all the applications (replace gname with what you want to get or * for all)
SELECT gname FROM applications

//Initially add the entries into applications
INSERT INTO applications (gname, gpoints, gpic, gviews) VALUES ('Flower', 250, '5_250.jpg', 301)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜