0

I have a table with field 'c_number' as primary key. now i have used this primary key as foreign key in two tables: calls and billing. can anyone help me why this query is not working

$q="select c_number, type, billing.days from calls, billing where calls.c_number=billing.c_number group by c_number";
$r=mysql_query($q);
while($row=mysql_fetch_array($r))
{
echo $row['days'];
}

the query doesnot work and gives me error as:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\vas1\b.php on line 61

line 61:

 while($row=mysql_fetch_array)
mary
  • 32
  • 6
  • The `mysql_*` functions are **no longer maintained** and shouldn't be used in any new codebase. It is being phased out in favor of newer APIs. Instead you should use [**prepared statements**](https://www.youtube.com/watch?v=nLinqtCfhKY) with either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). – tereško Mar 09 '14 at 10:14

2 Answers2

1

change ur while like this

$q="select c_number, type, billing.days from calls, billing where calls.c_number=billing.c_number group by c_number";
    $r=mysql_query($q);
    while($row=mysql_fetch_array($r))
    {
    echo $row['days'];
    }

Also, as a suggestion please note that Original MySQL API is deprecated , from the docs:

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

Here the docs for PDO

isJustMe
  • 5,384
  • 1
  • 29
  • 45
0

it gives error because you have not supplied the result to the mysql_fetch_array() function.

it should be like this: mysql_fetch_array($r)

also consider using quotes in the values in sql statement.

you will find several examples of mysql_fetch_array() in this link.

Hezbullah Shah
  • 820
  • 6
  • 16