View unanswered posts | View active topics It is currently Fri Oct 07, 2022 9:12 am



Reply to topic  [ 6 posts ] 
 Search queries help 
Author Message
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post Search queries help
Hi,

I am currently trying to do a search on google and php-editors to check if there're any existing threads regarding about creating a search query with 2 search values pass by POST method instead of one.

Anyone has any idea what is it called?


Tue Dec 08, 2009 12:57 am
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
I am trying to post 2 queries where user will type the relevant data in the search box and using the drop down list available to search in the database.

Can i do a search query like this:

Code:
$sql = "SELECT *
  FROM wsdevice, subcon
  WHERE wsdevice_num LIKE '%$val_d%' OR subname LIKE '%$val_sub'%";


Wed Dec 09, 2009 7:31 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Thanks.

Is it possible to do a search where user can either search by 1 value or search by 2 values in a single POST command?
in case my sentence is not clear, below is an example.

[HTML]
device search:
site search :


User can either search by device or by site and
can do a search by both entry.
[/HTML]

Can this be done?? if so, are there any examples available to have a look?


Sun Dec 13, 2009 9:10 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Thanks Xnuiem,

I am working on the code with a pagination script you altered for me few weeks ago.


How/Where do i include the $_GET['search'] for both values.

Previously:
[PHP]
$val_d = '';
if ($_POST['devicesearch']){ $val_d = $_POST['devicesearch']; }
else if ($_GET['search']){ $val_d = urldecode($_GET['search']); }

if ($val_d != '')
{
$sql = "SELECT *
FROM device
WHERE device_num LIKE '%$val_d%'";
.
.
.

echo "

[align=center]Page $pagenum of $last

"; // This shows the user what page they are on, and the total number of pages
if($pagenum>1)
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&search=" . urlencode($val_d) . "'>First</a> ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&search=" . urlencode($val_d) . "'><<</a>  ";
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else
{
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&search=" . urlencode($val_d) . "'>>></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&search=" . urlencode($val_d) . "'>Last</a> ";
[/PHP]

I had tried to do it in a similar way but it doesnt seem to work well.
NOW: [PHP]$val_d = '';
$val_sub='';
if ($_POST['device_search']){ $val_d = $_POST['device_search'];}
else if ($_GET['search']){ $val_d = urldecode($_GET['search']); }

if ($_POST['subconsite']){ $val_sub = $_POST['subconsite'];}
else if ($_GET['search']){ $val_sub = urldecode($_GET['search']); }

if (trim($val_d) != '' && trim($val_sub) != ''){
$sql = "select * from device";
if (trim($val_d) != ''){
$sql .= " where device_num like '%" . trim($val_d) . "%' ";
$where = true;
}
if (trim($val_sub) != ''){
if (!$where){
$sql .= " where subcon_site like '%" . trim($val_sub) . "%' ";
}
else {
$sql = str_replace("where ", "where (", $sql);
$sql .= " and subcon_site like '%" . trim($val_sub) . "%') or (device_num like '%" . trim($val_d . "%' or subcon_site like '%" . trim($val_sub) . "%')";
}
}
else {
die("NO SEARCH TERMS");
}

.
.
.
.

echo "

[align=center]Page $pagenum of $last

"; // This shows the user what page they are on, and the total number of pages
if($pagenum>1)
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&search=" . urlencode($val_d) . " + " . urlencode($val_sub) . "'>First</a> ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&search=" . urlencode($val_d) . " + " . urlencode($val_sub) . "'><<</a>  ";
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else
{
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&search=" . urlencode($val_d) . " + " . urlencode($val_sub) . "'>>></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&search=" . urlencode($val_d) . " + " . urlencode($val_sub) . "'>Last</a> ";

[/PHP]
I know something has to be changed here in order to view the search of both values. But i just cant figure out how to. can you assist me? Thanks


Mon Dec 14, 2009 9:06 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Form is:
[PHP]<form action="searchprocess.php" method="post">
<table border=0 cellspacing=1 cellpadding=3 bgcolor;"#353535"
align="center">
<tr>
<td bgcolor="#eeeeff" width="50%">
Device Number
</td>
<td bgcolor="#eeeeff" width="50%">
<INPUT type = "TEXT" name = "device_search">
</td>
</tr>
<td bgcolor="#eeeeff">
Subcon Release Site
</td>
<td bgcolor="#eeeeff">
<SELECT name="subconsite">
<option value=" "SELECTED></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="B1">B1</option>
<option value="B2">B2</option>
<option value="C">C</option>
<option value="C1">C1</option>
<option value="D">D</option>
<option value="E">E</option>
</SELECT>
</td>
<tr>
<td bgcolor ="eeeeff" colspan=2 align="center">
<INPUT Type="SUBMIT" name="submit" value="Device Search">
</td>
</tr>
</table>
</form>[/PHP]


Mon Dec 14, 2009 11:04 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Hi Xnuiem,

is this form ok?


Wed Dec 16, 2009 6:44 pm
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.