Jump to content

DillyDong

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

DillyDong's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Probably not the best way to fix it, but I just changed $i=2 and $i<=8 and it works.
  2. Hello, all, I've got a question I hope you can help me out with. I've got a database with two columns, one is called `the_question`, and the other is `the_answer`. Say the database looks like this: [code] +++++++++++++++++++++++++++++ |`the_question`|`the_answer`| |++++++++++++++++++++++++++++ |Apple        | Red        | |Banana        | Green      | |Grape        | Purple    | |Blueberry    | Blue      | |Cherry        | Red        | +++++++++++++++++++++++++++++ [/code] Now, what I want to do is have a form on a page where on the left-hand column, each value from `the_question` is listed, and on the right of each `the_question` value, there should be an input box where the user should enter the appropriate answer. Now, I want to pass this data to a new page via form action, and I want the next page to check the user's responses against the appropriate `the_answer`fields. I'm having trouble understanding exactly how to do this. The script I have for the first page is: [b]test_1.php[/b] [code] <form method="post" action="test_2.php"> <table> <tr><td>Apple</td><td><input type="text" name="(don't know what to put here)" /></td></tr> <tr><td>Banana</td><td><input type="text" name="(don't know what to put here)" /></td></tr> <tr><td>Grape</td><td><input type="text" name="(don't know what to put here)" /></td></tr> <tr><td>Blueberry</td><td><input type="text" name="(don't know what to put here)" /></td></tr> <tr><td>Cherry</td><td><input type="text" name="(don't know what to put here)" /></td></tr> </table> <input type="submit" value="Submit" /> </form> [/code] [b]test_2.php[/b] [code] <?php foreach($_POST as $value) { $data = $_POST; } foreach($data as $data_for_query) { $sql = "SELECT * FROM `table` WHERE `the_answer` = ".$data_for_query.";"; $query = mysql_query($sql); if(empty(mysql_num_rows($query))) { echo "Sorry, the correct answer was: " ; //And at this point, how do I get it to return the correct answer? All I passed through the form was user input :( else { echo "Good job."; } } ?> [/code] Any help would be greatly appreciated! I have no idea.
  3. How exactly does it not work? What's the error message? Is the file size too large?
  4. Shucks. Using [code]WHERE (`list_number` = 1 OR `list_number` = 3 OR `list_number` = 5)[/code] is also acceptable though, so any way to implement it with that sort of code?
  5. Hopefully this will remedy the problem: http://us3.php.net/error-reporting
  6. Hi all, sorry, I know the title is ambiguous, but I wasn't sure exactly how to explain it. Anyway, Say I have the following code: [code]'SELECT * FROM `table` WHERE `list_number` IN (1,3,5)[/code] Now, let's say that there are 20 rows for each matching `list_number` criteria (ie, There are 20 rows where `list_number` = 1, 20 rows where `list_number` = 3, and 20 rows where `list_number` = 5). What I would like to know is, how would I tell the MySQL query to get only 10 (in order or random, doesn't matter) rows for each `list_number`? I thought that LIMIT only worked for the entire query, not per where condition. Any help is appreciated! Thank you!
  7. Thanks for the simplified code! I never even knew the keyword "IN" existed!
  8. Dear wildteen88, Thanks a lot for the quick reply! That help was invaluable. Sincerely, DillyDong
  9. Hi all! Let's say I have the following ten checkboxes: [code]<input name="checkbox_1" type="checkbox" value="1" />   <input name="checkbox_2" type="checkbox" value="1" />   <input name="checkbox_3" type="checkbox" value="1" />   <input name="checkbox_4" type="checkbox" value="1" />   <input name="checkbox_5" type="checkbox" value="1" />   <input name="checkbox_6" type="checkbox" value="1" />   <input name="checkbox_7" type="checkbox" value="1" />   <input name="checkbox_8" type="checkbox" value="1" />   <input name="checkbox_9" type="checkbox" value="1" />   <input name="checkbox_10" type="checkbox" value="1" />[/code] Now, for each checkbox the user checks, I want to update a MySQL query that will get values from each list corresponding to that number. For example, if they check boxes 1 and 2, I want the MySQL query to look like: [code]"SELECT * FROM `table` WHERE (`list_number` = 1 OR `list_number` = 2)[/code]..etc How would I generate this MySQL query most efficiently with ten or more checkboxes? I was thinking of using [code]foreach()[/code] but I'm not sure if that's going to work. If someone could point me in the right direction that would be great! Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.