GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Jan-2005, 12:03
mojgan mojgan is offline
New Member
 
Join Date: Jan 2005
Posts: 1
mojgan is on a distinguished road

Advanced Search problem


Hi everybody,
I'm new in PHP. I've created a simple search code and it searches properly. My problem is that I wanna create an advanced search. I want to get country name from a drop down list and then search criteria for that specific country, but the only result I get is: 0
Would you please help me what can I do?

My sample code is:

PHP Code:

<?php
$searchstring=$_POST['searchstring']; 
if ($searchstring) 
{ 
$db=mysql_connect("localhost","username","password"); 
mysql_select_db("DBname",$db) ; 

$sql="SELECT DISTINCT countries.countries_name, countries.countries_id, users.* FROM users, countries WHERE country_id = '" . $row["countries_id"] . "' AND empl_status like '%$searchstring%' order by fname ASC"; 

$result=mysql_query($sql,$db) ; 
$num = mysql_num_rows($result); 

echo "<p>Your search criteria has <strong> $num </strong> result(s).<br/></p>"; 
while ($row=mysql_fetch_array($result)) 
{ 

echo "<li>" . $row["fname"]. "</li><br />\n"; 

} 

echo "<form method='POST' action='search.php'> 

<input type='submit' value='Search Again' name='B1'> 
</form>"; 
} 
else 
{ 
?> 

<form method="POST" action="<?php $PHP_SELF ?>"> 
<table broder="2" cellspacing="2"> 
<tr><td>Insert your search string here</td> 
</tr> 
<tr> 
<td><input type="text" name="searchstring" size="28"></td> 
</tr> 
</table> 
<p><input type="submit" value="Search" name="B1"><input type="reset" value="Reset"></p> 
</form> 

<? 
} 

?>


Thanks in advance.
Last edited by JdS : 24-Jan-2005 at 06:35. Reason: Please insert your PHP code between [php] & [/php] tags
  #2  
Old 24-Jan-2005, 06:47
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
I have no idea where you have set $row["countries_id"] in your script.

If the country id is being set through the form, then you can check for it and run your query accordingly. Like in this example:

PHP Code:

<?php

// get the search string from the form
$searchstring = mysql_escape_string( $_POST['searchstring'] );
if ($searchstring)
{
  $db=mysql_connect("localhost","username","password");
  mysql_select_db("DBname",$db) ;

  // build the bits off the sql string to search for the country id if set
  $sql_country  = null;
  if( $_POST['countries_id'] )
  {
    $_POST['countries_id'] = intval( $_POST['countries_id'] );
    $sql_country = "country_id = $_POST[countries_id] AND ";
  }

  $sql="SELECT DISTINCT countries.countries_name, countries.countries_id, users.* FROM users, countries WHERE {$sql_country}empl_status like '%$searchstring%' order by fname ASC";
?>

 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using meta tags help in ranking on some search engine pcx Search Engine Optimization Forum 8 29-Mar-2005 16:42
How to search an array problem jenmaz C Programming Language 4 17-Nov-2004 02:58
weird search problem!! JUNK KED Open Discussion Forum 3 11-Oct-2003 01:48
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 11:34
[class] 404 search function code jrobbio MySQL / PHP Forum 6 22-Apr-2003 10:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:11.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.