我的问题是,我没有从 mysql 获得任何产品。如果我回显 sql 查询,我会返回 3 行,这很好,因为我在 ID-12 类别中有 3 个产品。
如果回显 $category_id,我得到:12
我的代码有什么问题?我没有得到任何错误。
谢谢!
<?php
function render_category_page($category_id)
{
$id = (int)$this->$category_id;
$connect_to_mysql = my_conn();
if($connect_to_mysql == true )
{
get_product_data("SELECT * FROM products WHERE category_id = '".$id."'", $connect_to_mysql, $limit = 0);
if(get_product_data())
{
if(count_rows_of_sql(get_product_data) == 0 )
{
show_message("There are no rows in the table.");
}
else
{
show_message("There are '".count_rows_of_sql(get_product_data)."' rows in the table.");
$product = fetch_data_from_sql(get_product_data());
$category_id = (int)$product['category_id'];
$product_name = "<h1 class='product_name'>".cut_html_chars($product['product_name'])."</h1>";
$product_desricption = "<p class='product_desricption'>".cut_html_chars($product['product_desricption'])."</p>";
$product_full_content = "<div class='product_full_content'>".cut_html_chars($product['product_full_content'])."</div>";
$product_to_link = "<a href='".$this->$product_to_link."' class='product_to_link' title='".$this->$product_name."' target='_self'>".$this->$product['product_seo_url']."</a>";
for($i = 1; $i <= count_rows_of_sql(get_product_data); $i++)
{
$i++;
}
$products_in_category = (int)products_in_category($i);
}
}
else
{
log_message("The sql command didnt run.", $type = "sql", $write_to_file = 1);
write_error_message_to_file("./logs/error_logs/", $filename = $type . "-error" . date("Y-m-d-H:i:s") . generate_random_number($min = 1, $max = 9999), $fileType = "txt");
}
}
else
{
log_message("Cant connect to database.", $type = "sql", $write_to_file = 1);
write_error_message_to_file("./logs/error_logs/", $filename = $type . "-error" . date("Y-m-d-H:i:s") . generate_random_number($min = 1, $max = 9999), $fileType = "txt");
}
}
render_page($page_type = "category", $html = 1, $template = "bootsrap-4", $pagination = $products_in_category, $product_container_div = "product-container", render_category_page($category_id));
?>