Jump to content

Archived

This topic is now archived and is closed to further replies.

kaniniman

Using dynamic inputs from form to query mysql

Recommended Posts

I am trying to use dynamic inputs from a form to query mysql database. The table looks like below:

[table]
[tr][td]id[/td][td]question[/td][td]answer[/td][/tr]
[tr][td]1[/td][td]3[/td][td]2[/td][/tr]
[tr][td]2[/td][td]4[/td][td]4[/td][/tr]
[tr][td]5[/td][td]3[/td][td]2[/td][/tr]
[tr][td]5[/td][td]4[/td][td]4[/td][/tr]
[tr][td]5[/td][td]5[/td][td]5[/td][/tr]
[/table]

The above table is the result of inputs from the form. All I am trying to do is to create php code to go through the table and grab the "id" where (question=3 AND answer=2) and  (question=4 AND answer=4) and (question=5 AND answer=5) for all possible "id" for the condition specified.

Please help!

Share this post


Link to post
Share on other sites
[code]
<?php
  $q = 3;
  $a = 2;

  $sql = "select id from tablename where question = '$q' and answer = '$a'";
  $result = mysql_query($sql) or die (mysql_error());
 
  while ($list = mysql_fetch_array($result)) {
    echo "id is {$list['id']} <br>";
  }
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.