Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
thcc2
Forum Commoner
Posts: 33 Joined: Thu Jan 05, 2006 9:37 pm
Location: Singapore
Post
by thcc2 » Wed Jan 11, 2006 3:07 am
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?
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Thu Jan 12, 2006 11:33 am
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>'; ?
thcc2
Forum Commoner
Posts: 33 Joined: Thu Jan 05, 2006 9:37 pm
Location: Singapore
Post
by thcc2 » Fri Jan 13, 2006 12:26 am
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%'
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Fri Jan 13, 2006 12:32 am
So it working right ?
thcc2
Forum Commoner
Posts: 33 Joined: Thu Jan 05, 2006 9:37 pm
Location: Singapore
Post
by thcc2 » Fri Jan 13, 2006 12:36 am
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.
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Fri Jan 13, 2006 12:44 am
What was your pg_query like ?
Code: Select all
$res = pg_query($query) or die(pg_last_error());
thcc2
Forum Commoner
Posts: 33 Joined: Thu Jan 05, 2006 9:37 pm
Location: Singapore
Post
by thcc2 » Fri Jan 13, 2006 1:52 am
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
thcc2
Forum Commoner
Posts: 33 Joined: Thu Jan 05, 2006 9:37 pm
Location: Singapore
Post
by thcc2 » Fri Jan 13, 2006 2:03 am
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