PHP - Am I Asking The Impossible
First question: is the third line of code here even nessesary
Code: [Select] $_SESSION['asked']=array(); $catagories = array("easy", "medium", "hard"); $random = $catagories[mt_rand(0, count($catagories)-1)].mt_rand(1,5); while(in_array($random, $_SESSION['asked'])) { $random = $catagories[mt_rand(0, count($catagories)-1)].mt_rand(1,5); } $_SESSION['asked'][] = $random; This then generates one of 15 options (currently), those being easy1, easy2, easy3, easy4, easy5, medium1, medium2, medium3, medium4, medium5, hard1, hard2, hard3, hard4, hard5. My second question is, can I give this generator the ability to generate hard6, hard7, hard8, hard9 and hard10, while not generating anything higher than 5 with easy and medium? Similar TutorialsI have a dilemma. Maybe it's an easy fix but i just cant see the solution. My code already works without preparing the sql. The problem is preparing the sql and building the dynamic query. In a nut shell, I have a form with 10 different fields. And depending on which field gets data, I build my query so that it only works on the fields the user typed something into. let me summarize .... I have a basic query that starts off like this $updatestring = ""; $query = "UPDATE table a SET "; if field1 set then $updatestring = $updatestring . " field1 = field1val " if field2 set then $updatestring = $updatestring . " field2 = field1val " if field3 set then $updatestring = $updatestring . " field3 = field1val " if field4 set then $updatestring = $updatestring . " field4 = field1val " and so on .... Finally $query = $query . $updatestring which can end up looking like: UPDATE table a SET field1 = field1val, field3 = field1val .... depending on which fields were set. I take care of commas and so on. Like I said this works. However, to prepare the statement really complicates things because if it looks like this: UPDATE table a SET field1 = ? , field3 = ? how do I know which variable to bind to the param out of the 10 possible fields ? How do I build the string types and place them in the right order? Do you see my dilemma? mysqli_stmt_bind_param($stmt, 'ii', $field1val, $field3val); Any help would be appreciated. I will also post this in the mysql section. Thanks, JT then This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359577.0 |