Hey,
So I'm doing a search thingy and, user choose where to search inside site and it's done by ajax. I'm assuming if I show you code you'd understand better.
Ajax:
Classic AJAX request. Nothing too fancy.
PHP Code:
So the error is, I want to use foreach inside switch but it does not let me to do.
Any alternatives how may I do that?
Thanks.
So I'm doing a search thingy and, user choose where to search inside site and it's done by ajax. I'm assuming if I show you code you'd understand better.
Ajax:
Code:
$(document).ready(function() {
$('#searchBtn').click(function() {
var text = $('input#seachText').val();
var where = $('#where');
var where_text = where.text();
console.log(where_text);
$.ajax({
url: document.location+ '/habbo_archive/system/js/search.php',
method:'POST',
data: {
text:text,
where: where_text
},
beforeSend: function() {
$('#searchResults').text('Searching...');
},
success:function(results) {
$('#searchResults').text('');
$('#searchResults').html(results);
}
});
});
});
PHP Code:
PHP:
<?php
sleep(2);
if(!$_POST) {
die('hell no');
}
include('../config.php');
$where_post = $_POST['where'];
$text = $_POST['text'];
$folders = $db->prepare("SELECT * FROM folders");
$folders->execute();
$folders = $folders->fetchAll();
switch ($where_post) {
foreach($folders as $folder){
case $row:
$where = $row
break;
default :
$where = $row;
break;
}
}
$files = glob("../".$where."/*". $text ."*.*");
//var_dump(glob('*'));
if(count($files) > 0){
foreach($files as $file){
var_dump($files);
}
}
else {
die('no files found');
}
?>
Any alternatives how may I do that?
Thanks.