I have written this code to display list of items pulled out of a postgresql database, this is a bit lengthy code so I have put little bit of it here to figure out the problem I have. the result I get is given below`test1m
Resource id #4
Galle
Kandy
Anuradhapura
Dambulla
Hambantota
Colombo
Hikkaduwa
test2
Resource id #4
but expected one would be this
test1m
Resource id #4
Galle
Kandy
Anuradhapura
Dambulla
Hambantota
Colombo
Hikkaduwa
test2
Resource id #4 Galle
Kandy
Anuradhapura
Dambulla
Hambantota
Colombo
Hikkaduwa
Here is the code
$date = date("Y-m-d");
$dbh = pg_connect("host=localhost dbname= drupal_test user=usrx password=123");
if (!$dbh) {
die("Error in connection: " . pg_last_error());
}
$sql1 = "SELECT *
FROM node, modify_dates, node_counter
WHERE node.nid = modify_dates.nid
AND node.nid = node_counter.nid
AND modify_dates.nid = node_counter.nid
AND node_counter.totalcount < '1000'
AND node.type = 'city_guide'
ORDER BY modify_dates.lmd";
$sel1 = pg_query($sql1);
$sql2 = "SELECT *
FROM node, modify_dates, node_counter
WHERE node.nid = modify_dates.nid
AND node.nid = node_counter.nid
AND modify_dates.nid = node_counter.nid
AND node_counter.totalcount > '1000'
AND node.type = 'city_guide'
ORDER BY modify_dates.lmd";
$sel2 = pg_query($sql2);
if(pg_num_rows($sel1) > 0) {
echo "test1";
chooseItems($sel1);
} else if(pg_num_rows($sel2) > 0) {
echo "test1m<br/>";
chooseItems($sel2);
}
if(pg_num_rows($sel2) > 0) {
echo "test2<br/>";
chooseItems($sel2);
} else if(pg_num_rows($sel1) > 0) {
echo "test2m<br/>";
chooseItems($sel1);
}
function chooseItems($sel) {
echo $sel."<br/>";
$m = 0;
while($row = pg_fetch_array($sel)) {
echo $row['title']."<br/>";
$m = $m+1;
}
}
pg_close($dbh);