Page 1 of 1
PostgresSQL - search for data
Posted: Wed Jan 11, 2006 3:07 am
by thcc2
hi all,
is the following pSQL statement valid?
Code: Select all
$query = "select display_name, mobile_numb, level, class from address_book " .
"where display_name like '{$display_name}%'";
but while i
but it gives me the following result
select display_name, mobile_numb, level, class from address_book where display_name like '%' order by display_name
can someone tell me what's wrong?
Posted: Thu Jan 12, 2006 11:33 am
by anjanesh
Whats the output for
Code: Select all
echo $display_name.'<br>';
$query = "select display_name, mobile_numb, level, class from address_book where display_name like '$display_name%'";
echo $query.'<br>';
?
Posted: Fri Jan 13, 2006 12:26 am
by thcc2
anjanesh wrote:Whats the output for
Code: Select all
echo $display_name.'<br>';
$query = "select display_name, mobile_numb, level, class from address_book where display_name like '$display_name%'";
echo $query.'<br>';
?
i get the result of Terence
i get this
Code: Select all
select display_name, mobile_numb, level, class from address_book where display_name like 'terence%'
Posted: Fri Jan 13, 2006 12:32 am
by anjanesh
So it working right ?
Posted: Fri Jan 13, 2006 12:36 am
by thcc2
thcc2 wrote:anjanesh wrote:Whats the output for
Code: Select all
echo $display_name.'<br>';
$query = "select display_name, mobile_numb, level, class from address_book where display_name like '$display_name%'";
echo $query.'<br>';
?
i get the result of Terence
i get this
Code: Select all
select display_name, mobile_numb, level, class from address_book where display_name like 'terence%'
but with no result now.
Posted: Fri Jan 13, 2006 12:44 am
by anjanesh
What was your pg_query like ?
Code: Select all
$res = pg_query($query) or die(pg_last_error());
Posted: Fri Jan 13, 2006 1:52 am
by thcc2
anjanesh wrote:What was your pg_query like ?
Code: Select all
$res = pg_query($query) or die(pg_last_error());
this is my php code, can tell me what's wrong with it, y got no result appear
thks in advance
Code: Select all
if($_GET['submit'])
{
$display_name = $_GET['display_name'];
//echo $display_name.'<br>';
$query = "select display_name, mobile_numb, level, class from address_book where " .
"display_name like '$display_name%'";
//$query .= " order by display_name";
//echo $query.'<br>';
$pg_result = pg_query($dbconn, $query);
echo($query);
print ("<table width="525" cellspacing="1" cellpadding="3" border="0" bgcolor="#123456">");
print ("<tr>");
print ("<td bgcolor="#dfdfdf"><b>Name</b></td>");
print ("<td bgcolor="#dfdfdf"><b>phone no</b></td>");
print ("<td bgcolor="#dfdfdf"><b>Class</b></td>");
print ("</tr>");
$row = pg_fetch_row($pg_result);
while($row = pg_fetch_row($pg_result))
{
//echo "ha";
if(($row[4] == 1) or ($row[4] == ""))
{
$primaryPhone = $row[10];
$primaryEmail = $row[13];
}
if($row[4] == 2)
{
$primaryPhone = $row[20];
$primaryEmail = $row[23];
}
print("<tr>\n");
printf("<td bgcolor="#ffffff"> <a href="./search3.php?contactID=%s">%s, %s</a></td>\n", $rowcolor, $row[0], $row[1], $row[2]);
printf("<td bgcolor="#ffffff"> <a href="./search3.php?contactID=%s">%s</a></td>\n", $rowcolor, $row[0], $primaryPhone);
printf("<td bgcolor="#ffffff"> <a href="./search3.php?contactID=%s">%s</a></td>\n", $rowcolor, $row[0], $primaryEmail);
print("</tr>\n");
}
print ("<tr>");
print ("<th bgcolor="#dfdfdf"> </th>");
print ("<th bgcolor="#dfdfdf"> </th>");
print ("<th bgcolor="#dfdfdf"> </th>");
print ("</tr>");
print ("<tr>\n");
print ("<td colspan="3" align="right" bgcolor="#DFFFDF">\n");
print ("<a href="./search3.php?tab=?">Search Again</a>.");
print ("</td>\n");
print ("</tr>\n");
print ("</table>");
}
thks in advance
Posted: Fri Jan 13, 2006 2:03 am
by thcc2
anjanesh wrote:What was your pg_query like ?
Code: Select all
$res = pg_query($query) or die(pg_last_error());
i use the following
Code: Select all
$pg_result = pg_query($dbconn, $query);
echo($pg_result);
it returns resource id #4