Reputation: 99
I'm still learning php so please take it easy on me. This might sound a silly question for you guys.
Right so. I have categories lets say Blogs, eCommerce, Portfolios etc. Files according too. Blog.php etc.
I also have functions.php where all my functions are.
MYSQL database is where I store information from them files. Website information, descriptions etc.
I want to have 1 function that queries data from a website just about 1 category so then I can display it in Blogs.php, eCommerce.php etc. My function to query data from mysql looks like this.
This is an example:
function querying_category($category){
$db = DB::getInstance();
$all = $db->query('SELECT * FROM website WHERE category = {$category} ORDER BY id DESC');
if($all->count()){
foreach($all->results() as $website){
$web_data[] = $website;
}
}
return $web_data;
}
and then let's say in my blog.php would go like:
$category = 'blog';
$website = querying_category($category);
Could you please tell me what am I doing wrong? I want to declare a variable in my blog.php or ecommerce.php etc without rewriting the following query:
'SELECT * FROM website WHERE category = {$category} ORDER BY id DESC
Can I achieve it with passing in $category
as an argument in querying_category()
but declaring $category
in my blog.php or ecommerce.php?
Upvotes: 0
Views: 65
Reputation: 74217
It seems as if the editing I made to the question fixed the OP's problem.
There were a few lines of code that were not properly indented along with a few spelling mistakes.
As per the OP's request, this answer has been given in order to close the question.
However, this line return $web_data;
should have been return $website;
Upvotes: 1