Php call data $ prize_arr = array (
'0' => array ('id' => 1, 'degree' => 1, 'min' => 1, 'Max '=> 5, 'prize' => 'first name', 'V' => 1 ),
'1' => array ('id' => 2, 'degree' => 32, 'min' => 7, 'Max '=> 35, 'prize' => 'Don't be discouraged ', 'V' => 1 ),
'2' => array ('id' => 3, 'degree' => 62, 'min' => 37, 'Max '=> 65, 'prize' => 'do not lose heart and wish you good luck blank space', 'V' => 1 ),
'3' => array ('id' => 4, 'degree' => 92, 'min' => 67, 'Max '=> 95, 'prize' => 'good luck ', 'V' => 1 ),
'4' => array ('id' => 5, 'degree' => 122, 'min' => 97, 'Max '=> 125, 'prize' => 'Second prize ', 'V' => 89 ),
'5' => array ('id' => 6, 'degree' => 150, 'min' => 127, 'Max '=> 155, 'prize' => 'upgrade', 'V' => 1 ),
'6' => array ('id' => 7, 'degree' => 178, 'min' => 157, 'Max '=> 185, 'prize' => 'balance and luck first hide the gap in the middle ', 'V' => 1 ),
'7' => array ('id' => 8, 'degree' => 208, 'min' => 187, 'Max '=> 215, 'prize' => 'Luck first hiding ', 'V' => 1 ),
'8' => array ('id' => 9, 'degree' => 238, 'min' => 217, 'Max '=> 245, 'prize' => 'third prize ', 'V' => 1 ),
'9' => array ('id' => 10, 'degree' => 266, 'min' => 247, 'Max '=> 275, 'prize' => 'to refuel', 'V' => 1 ),
'10' => array ('id' => 11, 'degree' => 298, 'min' => 277, 'Max '=> 305, 'prize' => 'fill in the room and thank you for participating in the space', 'V' => 1 ),
'11' => array ('id' => 12, 'degree' => 330, 'min' => 307, 'Max '=> 335, 'prize' => 'Thank you for participating ', 'V' => 1)
);
How can this be called from the database? I have already filled in the database. I have tried to call the numbers and text.
Id xg degree min max prize chance this is the name of the database
Reply to discussion (solution)
....$rs = mysql_query("id, xg, degree, min, max, prize, chance from tbl_name");while($r = mysql_fetch_assoc($rs)) { $prize_arr[] = $r;}
....$rs = mysql_query("id, xg, degree, min, max, prize, chance from tbl_name");while($r = mysql_fetch_assoc($rs)) { $prize_arr[] = $r;}
$ Prize_arr = array (
....
...
...
};
Replace
$ Rs = mysql_query ("id, xg, degree, min, max, prize, chance from magic_config ");
While ($ r = mysql_fetch_assoc ($ rs )){
$ Prize_arr [] = $ r;
} Does not work?
I am a Cainiao. please advise!
$ Rs = mysql_query ("select id, xg, degree, min, max, prize, chance from tbl_name ");
Tbl_name is the table name.
Magic_config I have changed
/** Link database **/error_reporting (E_ALL &~ E_NOTICE); ob_start (); session_start (); require_once ("config. php "); header (" Content-Type: text/html; charset = utf-8 ");/** $ prize_arr = array ('error' => 'true ', 'success' => 'false', 'SN '=> 'null'); // This is the echo json_encode ($ prize_arr) that fails ); **/$ ac = $ _ REQUEST ['AC']; if ($ ac = 'activityuser _ sn ') {$ prize_arr = array ('success' => 'true'); // This is the echo json_encode ($ prize_arr) that is successfully filled in the order after submission );} else {$ order_sn = date ("Y "). date ("m "). date ("d "). date ("H "). date ("I "). date ("s "). rand ();/** we set the corresponding angle and odds based on the awards on the lottery disc. php constructs a multi-dimensional array $ prize_arr, array $ prize_arr, id is used to identify different awards, degree indicates the degree of rotation, min indicates the minimum angle of each award range in the disc, max indicates the maximum angle. for example, the minimum angle corresponding to the first prize is 0 and the maximum angle is 30. Here we set the max value to 1 and the max value to 29, it is to avoid pointing to the middle line of two adjacent awards after the lucky draw. Because multiple equal-7 prizes are set in the disc, we set the angle range for each equal-7 prize in the array. Prize indicates the content of the award, and v indicates the probability of winning the prize. we will find that the sum of the 12 awards in the array is 100. if the value of v is 1, the probability of winning the prize is 1%, and so on. Here I didn't use the rotation range of max and min, pointing directly to the degree ** // ** var prizeDeg = [6, 36, 66, 96,126,156,186,216,246,276,306,336]; // This is what I modified, in fact, it does not work. change 6 to 1, change 36 to 32, change 66 to 62, change 96 to 92, change 126 to 122, change 156 to 150, change 186 to 178, and change 216 to 208. change 266 to 306 and change 298 to 336 **/$ rs = mysql_query ("praisefeild, id, praisenumber, min, max, praisename, chance from magic_config "); while ($ r = mysql_fetch_assoc ($ rs) {$ prize_arr [] = $ r ;} /** about the winning probability algorithm **/function getR And ($ proArr) {$ result = ''; // The total probability precision of the probability array $ proSum = array_sum ($ proArr ); // probability array loop foreach ($ proArr as $ key => $ proCur) {$ randNum = mt_rand (1, $ proSum); if ($ randNum <= $ proCur) {$ result = $ key; break;} else {$ proSum-= $ proCur;} unset ($ proArr); return $ result;}/** function getRand () the matching id is calculated based on the probability set in the array. we can call getRand (). In the code, we call getRand () to receive the award after probability calculation. then, based on the angle range configured in the award, an angle value is generated between the minimum angle and the maximum angle, and construct an array, including angle and award prize, and finally output in json format. **/Foreach ($ prize_arr as $ key => $ val) {$ arr [$ val ['id'] = $ val ['V'];} $ rid = getRand ($ arr); // Obtain the award id based on the probability $ res = $ prize_arr [$ rid-1]; // Medium Award $ degree = $ res ['Degree']; $ min = $ res ['min']; $ max = $ res ['Max ']; /** if ($ res ['id'] = 7) {// 7th Prize $ I = mt_rand ); $ result ['angle '] = mt_rand ($ min [$ I], $ max [$ I]);} else {$ result ['angle '] = mt_rand ($ min, $ max ); // randomly generate an angle} $ result ['prize'] = $ res ['prize']; **/if ($ res ['id'] = 1) {$ result_arr = array ('error' => '', 'success '=> 'true', 'prizetype' => 1, 'SN '=> $ order_sn, 'MSG '=> $ res ['prize']); // This is successful} elseif ($ res ['id'] = 2) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 3) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 4) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 5) {$ result_arr = array ('error' => '', 'success '=> 'true', 'prizetype' => 5, 'SN '=> $ order_sn, 'MSG '=> $ res ['prize']); // This is successful} elseif ($ res ['id'] = 6) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 7) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 8) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 9) {$ result_arr = array ('error' => '', 'success '=> 'true', 'prizetype' => 9, 'SN '=> $ order_sn, 'MSG '=> $ res ['prize']); // This is successful} elseif ($ res ['id'] = 10) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 11) {$ result = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} elseif ($ res ['id'] = 12) {$ result_arr = array ('error' => 'true', 'success' => 'false', 'SN '=> 'null ', 'MSG '=> $ res ['prize']); // This is a failure} $ result_arr ['angle'] = mt_rand ($ min, $ max ); // Generate an angle randomly. this is the previous $ result_arr ['angle '] = $ degree; // directly generate a fixed angle echo json_encode ($ result_arr) in the array );}
Print_r ($ prize_arr );
Changed the database name.
Print_r ($ prize_arr );
$ Rs = mysql_query ("praisefeild, id, praisenumber, min, max, praisename, chance from magic_config ");
While ($ r = mysql_fetch_assoc ($ rs )){
Print_r ($ prize_arr );
} Is that true?
$ Rs = mysql_query ("select praisefeild, id, praisenumber, min, max, praisename, chance from magic_config ");
$ Rs = mysql_query ("select praisefeild, id, praisenumber, min, max, praisename, chance from magic_config ");
Amount
$ Rs = mysql_query ("select praisefeild, id, praisenumber, min, max, praisename, chance from magic_config ");
While ($ r = mysql_fetch_assoc ($ rs )){
$ Prize_arr [] = $ r;
} And
$ Rs = mysql_query ("select praisefeild, id, praisenumber, min, max, praisename, chance from magic_config ");
While ($ r = mysql_fetch_assoc ($ rs )){
Print_r ($ prize_arr );
} I have tried it, but I still cannot try it. $ rs = mysql_query ("select * praisefeild, id, praisenumber, min, max, praisename, chance from magic_config ..
// The database connection code $ rs = mysql_query ("select praisefeild, id, praisenumber, min, max, praisename, chance from magic_config") or die (mysql_error ()); while ($ r = mysql_fetch_assoc ($ rs) {$ prize_arr [] = $ r;} print_r ($ prize_arr );
// The database connection code $ rs = mysql_query ("select praisefeild, id, praisenumber, min, max, praisename, chance from magic_config") or die (mysql_error ()); while ($ r = mysql_fetch_assoc ($ rs) {$ prize_arr [] = $ r;} print_r ($ prize_arr );
$ Conn = @ mysql_connect ("localhost", "root", "q123456"); if ($ conn = null) die ("database connection failed "); mysql_query ("set names 'gb2312 '"); if (! Mysql_select_db ("zhuanpan") {die ("database connection failed");} $ rs = mysql_query ("select praisefeild, id, praisenumber, min, max, praisename, chance from magic_config ") or die (mysql_error (); while ($ r = mysql_fetch_assoc ($ rs) {$ prize_arr [] = $ r ;}The probability still cannot be controlled.