Search Function. NEED HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Search Function. NEED HELP!

Post by qdz90 »

I got this code, a friend of mine made this for me. it works though, but i need to modify it.

Code: Select all

<?php

$resultsxml = xml_read('projecten.xml');
$resultsxml = $resultsxml['result'];

$getLocatie = $_POST['location'];
$getFase = $_POST['fase'];
$getBor = $_POST['buyorrent'];




$last_results = array();

if(isset($getLocation)){
		
	$last_results = resultFilter($getLocation,$resultsxml);
	
}else{$last_results = $resultsxml;}

if(isset($getFase)){
				
	$last_results = resultFilter($getFase,$last_results);

}else{
	
	if(empty($getLocatie)){
		
		$last_results = $resultsxml;
	}
}

if(isset($getBor)){
	
	if($getBor != "both"){
		
		if($getBor== "buy"){
			
			$fase = "For Sell";
			
		}else if($getBor == "rent"){
			
			$fase = "For Rent";
			
		}
		
		$last_results = filterProjects($last_results, $fase);
	}
}
This code is used for a real estate website.

A house can have 3 stats the 'buyorrent': Rent, Sell, Both.

When you give the command to search for: rent it works fine.
when you give the command to search for: sell it works fine.
when you give the command to search for: both it works fine.

The problem is, that when you search for: rent, it wont display a real estate project that is marked "both" meaning rent and sell.
The same happends when you search for: buy, it wont display a real estate project that is marked "both" meaning rent and sell.


i aint no php-magic kid. i tried tough. red several tutorials about php but it wouldnt work. i think i figured out that the problem lies in this piece of code.

Code: Select all

if(isset($getBor)){
	
	if($getBor != "both"){
		
		if($getBor== "buy"){
			
			$fase = "For Sell";
			
		}else if($getBor == "rent"){
			
			$fase = "For Rent";
			
		}
Can anyone help me fix the code? So that when a command to search for rent or sell, it will display projects marked as "both" meaning rent and sell.

Thanks in advance!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search Function. NEED HELP!

Post by requinix »

Actually, seems to me that filterProjects() is what needs to be fixed. What does that code look like? And while I'm at it, what does the XML look like too?
qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Re: Search Function. NEED HELP!

Post by qdz90 »

Here's the code

Code: Select all

<?php

$resultsxml = xml_read('projecten.xml');
$resultsxml = $resultsxml['result'];

$getLocatie = $_POST['location'];
$getFase = $_POST['fase'];
$getBor = $_POST['buyorrent'];




$last_results = array();

if(isset($getLocation)){
		
	$last_results = resultFilter($getLocation,$resultsxml);
	
}else{$last_results = $resultsxml;}

if(isset($getFase)){
				
	$last_results = resultFilter($getFase,$last_results);

}else{
	
	if(empty($getLocation)){
		
		$last_results = $resultsxml;
	}
}

if(isset($getBor)){
	
	if($getBor != "both"){
		
		if($getBor== "buy"){
			
			$fase = "For Sell";
			
		}else if($getBor == "rent"){
			
			$fase = "For Rent";
			
		}
		
		$last_results = filterProjects($last_results, $fase);
	}
}


function filterProjects($var, $query){
	
	$results = array();
	
	foreach($var as $i => $val){
		$key = in_array($query, $var[$i]);
		if($key == 1){
			array_push($results, $val);
		}
	}
	return($results);
}


function resultFilter($post,$xml){
	$arr = array();
	for($i=0;$i<count($post);$i++){
		
		$query = $post[$i];
		$results = filterProjects($xml, $query);
		
		
		for($z=0;$z<count($results);$z++){
			array_push($arr, $results[$z]);
		}	
	}
	
	return($arr);
}


function xml_read($xml) {
    if (!$data = implode('', file($xml))) {
        die('kan xml document niet vinden!');
    }
    $parser = xml_parser_create();
    $params = array();
    $level = array();
    
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $values, $index);
    xml_parser_free($parser);
    
    foreach ($values as $element) {    
        switch($element['type']) {
            case 'open' :
                if (array_key_exists('attributes', $element)) {
                    list($level[$element['level']], $extra) = array_values($element['attributes']);
                }
                else { $level[$element['level']] = $element['tag']; }
                break;
                
            case 'complete' :
                $start = 1;
                   $exec = '$params';
                   while($start < $element['level']) {
                         $exec .= '[$level['.$start.']]';
                         $start++;
                   }
                   $exec .= '[$element[\'tag\']] = $element[\'value\'];';            
                   eval($exec);
                break;
        }
    }
    return $params;
}
?>

And this is what the xml looks like!

Code: Select all

<result>
	<project id="0">
		<titel>Project1</titel>
		<picture>path/thumb.jpg</pictre>
		<buyorrent>For Rent</buyorrent>
		<href>path</href>	
		<status>ontwerp</status>
		<provincie>Noord-Holland</provincie>
	</project>
	<project id="1">
		<titel>Project2</titel>
		<picture>path/thumb.jpg</pictre>
		<buyorrent>For Sell</buyorrent>
		<href>path</href>	
		<status>ontwerp</status>
		<provincie>Zuid-Holland</provincie>
	</project>
	<project id="2">
		<titel>Project3</titel>
		<picture>path/thumb.jpg</pictre>
		<buyorrent>Both</buyorrent>
		<href>path</href>	
		<status>ontwerp</status>
		<provincie>Noord-Holland</provincie>
	</project>
</results>
its used in a real estate website, it outputs the search queries. IM REALLY SUCK AT PHP! :banghead:

There are 3 search possibilities: Rent, Sell, Both.

now the code displays when searched for:

Rent: listings marked as "For Rent".
Buy: listings marked as "For Sell".
Both: listings marked "For Sell", AND, "For Rent".

Oke thats all fine ! BUT.

It needs to output the following:

Rent: listings marked as "For Rent", AND, marked as "Both" (because a listing marked both, is also for rent!)
Buy: listings marked as "For Sell", AND, marked as "Both" (because a listing marked both, is also for sale!)
Both: listings marked " For Sell", AND, "For Rent". ( this function is already working )


If this can be fixed, u be my greatest hero !! :D :D
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search Function. NEED HELP!

Post by requinix »

Are you running PHP 5?

If you don't know,

Code: Select all

echo PHP_VERSION;
qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Re: Search Function. NEED HELP!

Post by qdz90 »

used the echo PHP_VERSION;

this is the result!

5.2.6-1+lenny8.backend
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search Function. NEED HELP!

Post by requinix »

Before I continue:

Your XML is invalid. Two tags don't match up: result/results and picture/pictre. Do you know that? Can you fix it?

If you can,

Code: Select all

$resultsxml = new SimpleXMLElement("projecten.xml");

$filters = array();
if (!empty($_POST["location"])) {
	$filters[] = "provincie='" . htmlentities($_POST["location"], ENT_QUOTES) . "'";
}
if (!empty($_POST["fase"])) {
	$filters[] = "status='" . htmlentities($_POST["fase"], ENT_QUOTES) . "'";
}
if (!empty($_POST["buyorrent"])) {
	switch ($_POST["buyorrent"]) {
		case "buy":
			$filters[] = "(buyorrent='For Sell' or buyorrent='Both')";
			break;
		case "rent":
			$filters[] = "(buyorrent='For Rent' or buyorrent='Both')";
			break;
		case "both":
			break;
		default:
			break;
	}
}

$filters = (count($filters) ? "[" . implode(" and ", $filters) . "]" : "");
$results = $resultsxml->xpath("//project{$filters}");
$results will be an array of SimpleXMLElement objects.
qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Re: Search Function. NEED HELP!

Post by qdz90 »

The errors in the XML where made when i translated the most of the XML from dutch to english before i posted it.
The xml i am working with is OK.

I Really really really appreciatie the help and effort you put in to this!

I now will try to fit in the piece of code into the existing code i had.

And again, thanks thanks thanks!
qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Re: Search Function. NEED HELP!

Post by qdz90 »

It might sound stupid, but i tried to implement this code into the existing, but with no php skills at all, its kinda hard to know which part goes where, and what must be deleted.

So this is my last wish with this code!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search Function. NEED HELP!

Post by requinix »

With comments - compare to the code I posted:

Code: Select all

$resultsxml = new SimpleXMLElement(/* file name here */);

$filters = array();
if (!empty($_POST[/* the "location" from the form */])) {
        $filters[] = "(the 'location' node in the XML)='" . htmlentities($_POST[/* the "location" from the form */], ENT_QUOTES) . "'";
}
if (!empty($_POST[/* the "fase" from the form */])) {
        $filters[] = "(the 'fase' node in the XML)='" . htmlentities($_POST[/* the "fase" from the form */], ENT_QUOTES) . "'";
}
if (!empty($_POST[/* the "buy or rent" from the form */])) {
        switch ($_POST[/* the "buy or rent" from the form */]) {
                case /* "buy" string */:
                        $filters[] = "(( the 'buy or rent' node in the XML)=('for sell' string) or ( the 'buy or rent' node in the XML)=('both' string))";
                        break;
                case /* "rent" string */:
                        $filters[] = "(( the 'buy or rent' node in the XML)=('for rent' string) or ( the 'buy or rent' node in the XML)=('both' string))";
                        break;
                case /* "both" string */:
                        break;
                default:
                        break;
        }
}

$filters = (count($filters) ? "[" . implode(" and ", $filters) . "]" : "");
$results = $resultsxml->xpath("//(the 'project' node from the XML){$filters}");
The /*...*/ is PHP stuff to replace and the (...) stuff in the few strings are values and XML node names to replace.

If you're still not sure, what do (a) the HTML form and (b) the untranslated XML look like?
qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Re: Search Function. NEED HELP!

Post by qdz90 »

i managed to change that part that you explaned. But in the original code there must be replaced a piece, thats where my problem lies.

the original XML "projecten.xml" looks like this.

Code: Select all

<result>
	<project id="0">
		<titel>project 1</titel>
		<foto>project-1/thumb.jpg</foto>
		<prijs>150.000</prijs>
		<buyorrent>Te Huur</buyorrent>
		<href>project-1</href>	
		<status>ontwerp</status>
		<provincie>Noord-Holland</provincie>
	</project>
	<project id="1">
		<titel>project 2</titel>
		<foto>project-2/thumb.jpg</foto>
		<prijs>200.000</prijs>
		<buyorrent>Te Koop</buyorrent>
		<href>project-2</href>
		<status>verkoop</status>
		<provincie>Utrecht</provincie>
	</project>
	<project id="2">
		<titel>project 3</titel>
		<foto>project-3/thumb.jpg</foto>
		<prijs>250.000</prijs>
		<buyorrent>Te Koop</buyorrent>
		<href>project-3</href>
		<status>bouw</status>
		<provincie>Zuid-Holland</provincie>
	</project>
</result>
Now the new PHP code should be implemented into the existing PHP Code of the page.

Code: Select all

<?php

$resultsxml = xml_read('projecten.xml');
$resultsxml = $resultsxml['result'];

$getLocatie = $_POST['locatie'];
$getFase = $_POST['fase'];
$getBor = $_POST['buyorrent'];




$last_results = array();

if(isset($getLocatie)){
		
	$last_results = resultFilter($getLocatie,$resultsxml);
	
}else{$last_results = $resultsxml;}

if(isset($getFase)){
				
	$last_results = resultFilter($getFase,$last_results);

}else{
	
	if(empty($getLocatie)){
		
		$last_results = $resultsxml;
	}
}

if(isset($getBor)){
	
	if($getBor != "beide"){
		
		if($getBor== "koop"){
			
			$fase = "Te Koop";
			
		}else if($getBor == "huur"){
			
			$fase = "Te Huur";
			
		}
		
		$last_results = filterProjects($last_results, $fase);
	}
}


function filterProjects($var, $query){
	
	$results = array();
	
	foreach($var as $i => $val){
		$key = in_array($query, $var[$i]);
		if($key == 1){
			array_push($results, $val);
		}
	}
	return($results);
}


function resultFilter($post,$xml){
	$arr = array();
	for($i=0;$i<count($post);$i++){
		
		$query = $post[$i];
		$results = filterProjects($xml, $query);
		
		
		for($z=0;$z<count($results);$z++){
			array_push($arr, $results[$z]);
		}	
	}
	
	return($arr);
}


function xml_read($xml) {
    if (!$data = implode('', file($xml))) {
        die('kan xml document niet vinden!');
    }
    $parser = xml_parser_create();
    $params = array();
    $level = array();
    
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $values, $index);
    xml_parser_free($parser);
    
    foreach ($values as $element) {    
        switch($element['type']) {
            case 'open' :
                if (array_key_exists('attributes', $element)) {
                    list($level[$element['level']], $extra) = array_values($element['attributes']);
                }
                else { $level[$element['level']] = $element['tag']; }
                break;
                
            case 'complete' :
                $start = 1;
                   $exec = '$params';
                   while($start < $element['level']) {
                         $exec .= '[$level['.$start.']]';
                         $start++;
                   }
                   $exec .= '[$element[\'tag\']] = $element[\'value\'];';            
                   eval($exec);
                break;
        }
    }
    return $params;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Overzicht van bedrijfsruimte te koop en te huur in Nederland in de conceptfase, ontwikkelfase, bouwfase of per direct beschikbaar"/>
<meta name="keyword" content="bedrijfsruimte, winkelruimte, kantooruimte, bedrijf, winkel, kantoor, te huur, te koop, nederland, amsterdam, rotterdam, den haag, amersfoort, berkel en rodenrijs"/>
<link href="../assets/css/style-red.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="RSS [Templates]" href="http://feeds2.feedburner.com/themecss" />
<link rel="shortcut icon" href="http://www.themecss.com/img/favicon.ico" />
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-18513715-1']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!--[if lt IE 7]>
	<script type="text/javascript" src="../assets/js/unitpngfix.js"></script>
<![endif]--> 

<title>Bedrijfsnieuwbouw.nl - Overzicht bedrijfsruimten in alle stadia van de ontwikkeling.</title>
</head>

<body class="subpage">

<? include ('../include/menu-projecten.php') ?>

<!--PROJECTEN-->

    <div class="sell-properties-red clear">
    	<h2>Bedrijfsruimten</h2>
        <p>Overzicht Bedrijfsnieuwbouw</p>
    	<div class="sell clear">
			<?php
			
				if(count($last_results) < 1){
					echo '	<h3>Sorry, er zijn geen projecten gevonden in uw criteria..</h3> 
								Klik <a class="terug" href="../">hier</a> om terug te gaan naar de vorige pagina.
							';
				}

				$z = 4;
				$first = true;
				
				
				
				for ($i = 0; $i < count($last_results); $i++) {
				
					$titel = $last_results[$i]['titel'];
					$foto = $last_results[$i]['foto'];
					$prijs = $last_results[$i]['prijs'];
					$buyorrent = $last_results[$i]['buyorrent'];							
					$tekst = $last_results[$i]['tekst']; 
					$href = $last_results[$i]['href']; 
					$provincie = $last_results[$i]['provincie']; 
					
					if(isset($last_results[$i]['status'])){
						$status = $last_results[$i]['status'];
					}else{
						$status = null;
					}
				?>
				
				<div class="sell-box<?php if($i == 0){ echo '-first';} if($i == $z){echo '-first';$z = $z +4;} ?>">
				
					<div class="sell-photo">
					
						<?php 
							if(isset($status)){
								
								if($status == 'ontwerp'){
									$text = 'Ontwerpfase';
									$color = '#ed1e24';
								}else if($status == 'verkoop'){
									$text = 'Verkoopfase';
									$color = '#3f55a5';
								}else if($status == 'verhuur'){
									$text = 'Verhuurfase';
									$color = '#3f55a5';		
								}else if($status == 'bouw'){
									$text = 'Bouwfase';
									$color = '#edc01e';
								}else if($status == "direct"){
									$text = 'Direct beschikbaar';
									$color = '#77c045';
								}else{
									$text = 'Status onbekend';
									$color = 'black';
								}
								
								echo '<a href=" ' . $href . ' " class="sell-label" style="background: '  . $color . ' ;">';

									echo $text;	
																
								echo '</a>';
							}
						?>

						<a href="<?php echo $href; ?>"><img src="<?php echo $foto; ?>" alt="" title="" /></a>

					</div>
					<ul>
						<li class="title"><?php echo $titel; ?></li>
						<li class="title" style="font-size:12px;font-weight:100;"><?php echo $provincie; ?></li>
						<li class="title" style="font-size:12px;font-weight:100;"><?php echo $buyorrent; ?></li>
				   <!-- <li class="price"><?php echo $prijs; ?></li> -->
						<li><?php echo $tekst; ?></li>
						<li><a href="<?php echo $href; ?>"></a></li>
					</ul>	               
				</div>
				<?php
				} 
			?>
        </div> 
    </div> 
 	<div class="navigation clear">
        	<ul> 
            	<li><span>Page 1 of 2</span></li>
                <li><a href="#" class="active-nav">1</a></li>
                <li><a href="#">2</a></li>
                <li><span>...</span></li>
                <li><a href="#">&raquo;</a></li>
                <li><a href="#">Last</a></li>
            </ul>
        </div>    
</div> 
<div class="bottom-container-red">	
	<div class="sold-red">
    	<h2>UITGELICHT</h2>
    	<ul class="clear">
			<?php
			$parsed = xml_read('../include/uitgelicht.xml');
			$parsed = $parsed['result'];
			for ($i = 0; $i < count($parsed); $i++) {
			?>
			<li><a href="../<?php echo $parsed[$i]['href']; ?>" class="tooltip" title="<?php $parsed[$i]['titel']; ?>"><img src="../<?php echo $parsed[$i]['foto']; ?>" alt="" title="" /></a></li>  <?php } ?>
         </ul>	
    </div>
</div>

<!--FOOTER CONTAINER-->

<?php include ('../include/footer.php') ?>



</body>
</html>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search Function. NEED HELP!

Post by requinix »

There's no "Both" in that XML - just buy and rent. What does it say if it's for buy and rent? "Beide"?
qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Re: Search Function. NEED HELP!

Post by qdz90 »

When its for Buy and Sell its says "Te koop en Te huur" meaning "For sell and For Rent" so today you learned a bit dutch :D.

I managed to fix that part, so that your php understands my XML.

But your code must go somewhere in my page, but i dont exactly get where and how!

You changed the code i had. But the new and the old are'nt "merged" yet. Thats my problem
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search Function. NEED HELP!

Post by requinix »

Code: Select all

<?php

$resultsxml = new SimpleXMLElement("projecten.xml");

$filters = array();
if (!empty($_POST["locatie"])) {
        $filters[] = "provincie='" . htmlentities($_POST["locatie"], ENT_QUOTES) . "'";
}
if (!empty($_POST["fase"])) {
        $filters[] = "status='" . htmlentities($_POST["fase"], ENT_QUOTES) . "'";
}
if (!empty($_POST["buyorrent"])) {
        switch ($_POST["buyorrent"]) {
                case "koop":
                        $filters[] = "(buyorrent='Te Koop' or buyorrent='Te koop en Te huur')";
                        break;
                case "huur":
                        $filters[] = "(buyorrent='Te Huur' or buyorrent='Te koop en Te huur')";
                        break;
                case "beide":
                        break;
                default:
                        break;
        }
}

$filters = (count($filters) ? "[" . implode(" and ", $filters) . "]" : "");
$results = $resultsxml->xpath("//project{$filters}");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Overzicht van bedrijfsruimte te koop en te huur in Nederland in de conceptfase, ontwikkelfase, bouwfase of per direct beschikbaar"/>
<meta name="keyword" content="bedrijfsruimte, winkelruimte, kantooruimte, bedrijf, winkel, kantoor, te huur, te koop, nederland, amsterdam, rotterdam, den haag, amersfoort, berkel en rodenrijs"/>
<link href="../assets/css/style-red.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="RSS [Templates]" href="http://feeds2.feedburner.com/themecss" />
<link rel="shortcut icon" href="http://www.themecss.com/img/favicon.ico" />
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-18513715-1']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!--[if lt IE 7]>
        <script type="text/javascript" src="../assets/js/unitpngfix.js"></script>
<![endif]-->

<title>Bedrijfsnieuwbouw.nl - Overzicht bedrijfsruimten in alle stadia van de ontwikkeling.</title>
</head>

<body class="subpage">

<? include ('../include/menu-projecten.php') ?>

<!--PROJECTEN-->

    <div class="sell-properties-red clear">
        <h2>Bedrijfsruimten</h2>
        <p>Overzicht Bedrijfsnieuwbouw</p>
        <div class="sell clear">
                        <?php
                       
                                if(count($results) < 1){
                                        echo '  <h3>Sorry, er zijn geen projecten gevonden in uw criteria..</h3>
                                                                Klik <a class="terug" href="../">hier</a> om terug te gaan naar de vorige pagina.
                                                        ';
                                }

                                $z = 4;
                                $first = true;
                               
                               
                               
                                for ($i = 0; $i < count($results); $i++) {
                               
                                        $titel = (string)$results[$i]->titel;
                                        $foto = (string)$results[$i]->foto;
                                        $prijs = (string)$results[$i]->prijs;
                                        $buyorrent = (string)$results[$i]->buyorrent;                                                   
                                        /* $tekst = (string)$results[$i]->tekst; -- not in the XML */ $tekst = null;
                                        $href = (string)$results[$i]->href;
                                        $provincie = (string)$results[$i]->provincie;
                                       
                                        if(isset($results[$i]->status)){
                                                $status = (string)$results[$i]->status;
                                        }else{
                                                $status = null;
                                        }
                                ?>
                               
                                <div class="sell-box<?php if($i == 0){ echo '-first';} if($i == $z){echo '-first';$z = $z +4;} ?>">
                               
                                        <div class="sell-photo">
                                       
                                                <?php
                                                        if(isset($status)){
                                                               
                                                                if($status == 'ontwerp'){
                                                                        $text = 'Ontwerpfase';
                                                                        $color = '#ed1e24';
                                                                }else if($status == 'verkoop'){
                                                                        $text = 'Verkoopfase';
                                                                        $color = '#3f55a5';
                                                                }else if($status == 'verhuur'){
                                                                        $text = 'Verhuurfase';
                                                                        $color = '#3f55a5';            
                                                                }else if($status == 'bouw'){
                                                                        $text = 'Bouwfase';
                                                                        $color = '#edc01e';
                                                                }else if($status == "direct"){
                                                                        $text = 'Direct beschikbaar';
                                                                        $color = '#77c045';
                                                                }else{
                                                                        $text = 'Status onbekend';
                                                                        $color = 'black';
                                                                }
                                                               
                                                                echo '<a href=" ' . $href . ' " class="sell-label" style="background: '  . $color . ' ;">';

                                                                        echo $text;    
                                                                                                                               
                                                                echo '</a>';
                                                        }
                                                ?>

                                                <a href="<?php echo $href; ?>"><img src="<?php echo $foto; ?>" alt="" title="" /></a>

                                        </div>
                                        <ul>
                                                <li class="title"><?php echo $titel; ?></li>
                                                <li class="title" style="font-size:12px;font-weight:100;"><?php echo $provincie; ?></li>
                                                <li class="title" style="font-size:12px;font-weight:100;"><?php echo $buyorrent; ?></li>
                                   <!-- <li class="price"><?php echo $prijs; ?></li> -->
                                                <li><?php echo $tekst; ?></li>
                                                <li><a href="<?php echo $href; ?>"></a></li>
                                        </ul>                  
                                </div>
                                <?php
                                }
                        ?>
        </div>
    </div>
        <div class="navigation clear">
                <ul>
                <li><span>Page 1 of 2</span></li>
                <li><a href="#" class="active-nav">1</a></li>
                <li><a href="#">2</a></li>
                <li><span>...</span></li>
                <li><a href="#">&raquo;</a></li>
                <li><a href="#">Last</a></li>
            </ul>
        </div>    
</div>
<div class="bottom-container-red">     
        <div class="sold-red">
        <h2>UITGELICHT</h2>
        <ul class="clear">
						<?php
						$parsed = new SimpleXMLElement("../include/uitgelicht.xml");
                        foreach ($parsed->result as $result) {
                        ?>
                        <li><a href="../<?php echo (string)$result->href; ?>" class="tooltip" title="<?php (string)$result->titel; ?>"><img src="../<?php echo (string)$result->foto; ?>" alt="" title="" /></a></li>  <?php } ?>
         </ul> 
    </div>
</div>

<!--FOOTER CONTAINER-->

<?php include ('../include/footer.php') ?>



</body>
</html>
I didn't see a "tekst" in the XML. What's up with that?
qdz90
Forum Newbie
Posts: 9
Joined: Thu Nov 04, 2010 6:59 am

Re: Search Function. NEED HELP!

Post by qdz90 »

I must be the hardest one to help!

What do you mean with no "tekst" ?

The XML is only to provide information for the overview of the projects, there is a page that displays al the projects. In the xml the info about the projects like:

- name
- location
- fase: design, building, sale, or available
- buy or rent.

So there is no tekst besides that.

Put the file online:

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /public/sites/www.bedrijfsnieuwbouw.nl/projecten/index.php on line 3

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: projecten.xml in /public/sites/www.bedrijfsnieuwbouw.nl/projecten/index.php on line 3

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /public/sites/www.bedrijfsnieuwbouw.nl/projecten/index.php on line 3

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /public/sites/www.bedrijfsnieuwbouw.nl/projecten/index.php:3 Stack trace: #0 /public/sites/www.bedrijfsnieuwbouw.nl/projecten/index.php(3): SimpleXMLElement->__construct('projecten.xml') #1 {main} thrown in /public/sites/www.bedrijfsnieuwbouw.nl/projecten/index.php on line 3



Man i should be paying you for al this help! :oops:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Search Function. NEED HELP!

Post by requinix »

Oops. Forgot.

Code: Select all

$resultsxml = new SimpleXMLElement(file_get_contents("projecten.xml"));
// and near the bottom,
$parsed = new SimpleXMLElement(file_get_contents("../include/uitgelicht.xml"));

Your original code had

Code: Select all

$tekst = $last_results[$i]['tekst'];

<li><?php echo $tekst; ?></li>
but the XML you posted doesn't have any "tekst" in it.
Post Reply