0

I have 2 table in a database

reffQuestion               

ID  QUESTION                  
1   Your pet                  
2   Your fav food              
3   Your hobbies
4   Your fav color
reffAnswer

IDS ANSWER
1   Cat
2   Pizza
3   Sport
4   Blue

It is possible if I write row["1"]; then it shows the value of ANSWER

I wrote:

$SQL = "SELECT A.ID from reffQuestion A
        INNER JOIN reffAnswer B on B.IDS = A.ID"

$res = mysql_query($SQL);
while ($row = mysql_fetch_assoc($res)){
        $i++;
        $answer[$i] =  $row['answer'];
}
CDspace
  • 2,639
  • 18
  • 30
  • 36
Pandu
  • 1
  • 3
    **Please**, don't use `mysql_*` functions for new code. They are no longer maintained and the community has begun the [deprecation process](http://news.php.net/php.internals/53799), and `mysql_*` functions have been officially removed in PHP 7. Instead you should learn about [prepared statements](https://en.wikipedia.org/wiki/Prepared_statement) and use either `PDO` or `mysqli_*`. If you can't decide, [this article will help to choose your best option](http://php.net/manual/en/mysqlinfo.api.choosing.php). – GrumpyCrouton Oct 10 '17 at 18:32
  • Yes, but you need to update your query to retrieve the columns you want to output. Right now, you're only selecting `A.ID`. Try `SELECT *...` – waterloomatt Oct 10 '17 at 18:37
  • You are not selecting anything from `reffAnswer` and you didn't use the `semi-colon`at the end of the quey. Try this: `$sql = " SELECT A.ID, B.* FROM reffQuestion A INNER JOIN reffAnswer B on B.IDS = A.ID";` – Diéfani Favareto Piovezan Oct 10 '17 at 19:28
  • @waterloomatt It's generally [not a good idea to use the `*` selector](https://stackoverflow.com/questions/3639861/why-is-select-considered-harmful?noredirect=1&lq=1). – GrumpyCrouton Oct 10 '17 at 19:40
  • Sorry you need to https://www.w3schools.com/sql/default.asp. And http://php.net/manual/en/book.mysqli.php. mysql_ is a NONO. – Nic3500 Oct 10 '17 at 23:58
  • thank you very much for all you guys...its very helpful.. – Pandu Oct 11 '17 at 16:50

0 Answers0