Searching with XML

Discussion in 'PHP' started by adamjblakey, Aug 30, 2007.

  1. #1
    Hi,

    I have been given an XML database to work with which i have never worked with before. What i need to do is convert the following php code to work with an XML database?

    <?php
    	$search_text=trim($_POST['search_text']);
    
    		$kt=split(" ",$search_text);//Breaking the string to array of words
    			// Now let us generate the sql 
    		while(list($key,$val)=each($kt)){
    		if($val<>" " and strlen($val) > 0){$q .= " title like '%$val%' or ";}
    									
    		$q=substr($q,0,(strLen($q)-3));
    		// this will remove the last or from the string. 
    		$query="select * from news where $q ";
    		$nt=mysql_query($query);
    		$countrowssa = mysql_num_rows($nt);
    			if ($countrowssa < 1){
    				echo "Sorry there are no results matching your search criteria, Please try again.";
    								 }
    				echo mysql_error();
    			while($row=mysql_fetch_array($nt)){
    
      print $row[title];
    	
    		} // End if form submitted
    ?>
    Code (markup):
    Any ideas how i can get this to work with an XML database?

    Cheers,
    Adam
     
    adamjblakey, Aug 30, 2007 IP
  2. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Anyone know how i would do this?
     
    adamjblakey, Aug 31, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    I think you're not describing clearly enough what you want to do. Also, an example of this XML database would be quite helpful.
     
    nico_swd, Aug 31, 2007 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Basically the top example of code searches a table called news in an SQL database.

    I want to use this same code but in place of searching a table in an SQL database i want to search a XML database called db.xml
     
    adamjblakey, Aug 31, 2007 IP