PDA

View Full Version : سوال: مشکل در دریافت داده از دیتابیس در حضور دستور LIKE



amirmohammad76
چهارشنبه 09 تیر 1395, 01:02 صبح
با سلام خدمت دوستان ، من برای دریافت مطالبی که در یک دسته بندی قرار دارن صفحه زیر رو کد نویسی کردم، اول این رو هم بگم که دسته بندی های مطلب اگر بیش از یکی باشد با کارکتر "," از هم جدا میشن و مشکل همینجاست که وقتی دسته بندی ها بیش از 1 میشه با ارور Notice: Undefined variable: catTemp in C:\xampp\htdocs\wn-category.php on line 23 مواجه میشم البته یه ارور دیگه هم که مربوط به فایل کلس هست میده و اون هم این هستش : Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\engine\template.class.php on line 27
حالا من هر کاری که میکنم نمیتونم مشکل رو حل کنم.

<?php
/** * @author AmirMohammad * @copyright 2016 */
if(file_exists("config.php")){ include("wn-head.php"); if(isset($_GET['cat']) && ($_GET['cat'] !== null)){ $catQuery = mysql_query("SELECT * FROM posts WHERE category LIKE '{$_GET['cat']}'"); if(mysql_num_rows($catQuery)){ $catArrays = array(); while($catrow = mysql_fetch_array($catQuery)){ $catArrays[] = $catrow; } foreach($catArrays as $cat){ $row = new Template("{$tpl_dir}/post.tpl"); foreach ($cat as $key => $value) { $row->set($key, $value); } $catTemp[] = $row; } $runFunc = Template::merge($catTemp); } else { $runFunc = "مطلبی در این دسته بندی وجود ندارد"; } } include("wn-run/winIndex.php");} else { header('location: /');}?>
اینم فایل class هستش :

<?php class Template { protected $file; protected $values = array(); public function __construct($file) { $this->file = $file; } public function set($key, $value) { $this->values[$key] = $value; } public function output() { if (!file_exists($this->file)) { return "Error loading template file ($this->file).<br />"; } $output = file_get_contents($this->file); foreach ($this->values as $key => $value) { $tagToReplace = "[@$key]"; $output = str_replace($tagToReplace, $value, $output); }
return $output; } static public function merge($templates, $separator = "\n") { $output = ""; foreach ($templates as $template) { $content = (get_class($template) !== "Template") ? "Error, incorrect type - expected Template." : $template->output(); $output .= $content . $separator; } return $output; } public function newConnection($table,$name,$w,$wt){ $Query = mysql_query("SELECT * FROM {$table} WHERE {$w} = {$wt} ORDER BY id DESC"); $Arrays.$name = array(); while($row = mysql_fetch_array($Query,MYSQL_ASSOC)){ $Arrays.$name[] = $row; } } }

?>

amirmohammad76
پنج شنبه 10 تیر 1395, 22:01 عصر
هيچ كس نيست جواب ِ منو بتونه بده ؟