Lazarus Rising
Lazarus Rising

Reputation: 2685

postgresql select query not working

I have a table lecturer with a column name and another department. I know for sure that one of the entries is name='Denis' and department='007'. This is the code:

<?php 
      $names; $surname;
    require_once('connect_db.php'); 
    $firstname = pg_query(connect(), "SELECT name FROM keep_track");
    while($row = pg_fetch_array($firstname)){ $names = $row['path']." ".$row['name'];    }
    $lastname = pg_query(connect(), "SELECT surname FROM keep_track");
    while($row = pg_fetch_array($lastname)){ $surname = $row['path']." ".$row['surname'];    }

           echo '<div id="show_dialog" class="ui-dialog-content ui-widget-content">';            
        echo "Lecturer: ".$names." ".$surname."<br>Department: ";

        require_once('connect_db.php'); 
        $a = pg_query(connect(), "SELECT department FROM lecturer WHERE name='$name'");
            while($row = pg_fetch_array($a)){ echo "Hi!!!";    }

        echo '</div>';
?>

But it doesnt echo anything. The variable $names has already been set and echoed in previous lines successfully and its value was set as John. The other queries Ive done are working fine. Idk why this one is not.

Update: OK, I know why it doesn't work, but idk how to fix it. The problem is in this line:

 $a = pg_query(connect(), "SELECT department FROM lecturer WHERE name='$name'");

I need to compare column name with variable $name, but it won't work like that. What is the right syntax? I am looking, but i havent been very successful till now

Upvotes: 1

Views: 2803

Answers (1)

Nebojsa Susic
Nebojsa Susic

Reputation: 1260

I will try following..

require_once('connect_db.php'); 
$query = "SELECT department FROM lecturer WHERE name='$name'";
echo $query;
$a = pg_query(connect(), $query);

and will try to execute echoed query directly from some postgresql manager (or psql).

Upvotes: 1

Related Questions