/** * Get all records from the ad regarding the given filters * Set the picture and thumb value for every record. * * @param array $filters[optional] Key value pairs for filtering the result. * @param string $text_filter[optional] Sql expression needs to be inserted to the WHERE clause of the query. * @param int $limit[optional] Number of rows needs to be returned. * @param string $order_by[optional] The designated row order. If not given then the table's default order vill be used. * @return array The result rows as array. */ public static function get_all($filters = array(), $text_filter = '', $limit = '', $order_by = '') { global $db, $upload_path; $filter = ''; foreach ($filters as $key => $value) { $filter .= " AND {$key}='{$value}'"; } if ($text_filter != '') { $text_filter = "AND {$text_filter}"; } if ($order_by == '') { $order_by = static::$default_order; } if ($limit != '') { $limit = "LIMIT {$limit}"; } $db->sql = "SELECT id," . static::$table_columns . ", \n\t\t\t\t\t(SELECT r.parent FROM category r WHERE r.id=category) as category_parent,\n\t\t\t\t\t(SELECT r.id FROM category r WHERE r.id=category) as category_id1, \n\t\t\t\t\t(SELECT r.id FROM category r WHERE r.id=category_parent) as category_id2,\n\t\t\t\t\t(SELECT IF(category_parent=0,category_id1,category_id2)) as main_category_id,\n\t\t\t\t\t(SELECT IF(category_parent=0,0,category_id1)) as sub_category_id,\n\t\t\t\t\t(SELECT r.name FROM category r WHERE r.id=main_category_id) as main_category,\n\t\t\t\t\t(SELECT r.slug FROM category r WHERE r.id=main_category_id) as main_category_slug,\n\t\t\t\t\t(SELECT r.name FROM category r WHERE r.id=sub_category_id) as sub_category,\n\t\t\t\t\t(SELECT r.slug FROM category r WHERE r.id=sub_category_id) as sub_category_slug,\n\t\t\t\t\t(SELECT r.parent FROM region r WHERE r.id=region) as region_parent,\n\t\t\t\t\t(SELECT r.id FROM region r WHERE r.id=region) as region_id1, \n\t\t\t\t\t(SELECT r.id FROM region r WHERE r.id=region_parent) as region_id2,\n\t\t\t\t\t(SELECT IF(region_parent=0,region_id1,region_id2)) as main_region_id,\n\t\t\t\t\t(SELECT IF(region_parent=0,0,region_id1)) as sub_region_id,\n\t\t\t\t\t(SELECT r.name FROM region r WHERE r.id=main_region_id) as main_region,\n\t\t\t\t\t(SELECT r.slug FROM region r WHERE r.id=main_region_id) as main_region_slug,\n\t\t\t\t\t(SELECT r.name FROM region r WHERE r.id=sub_region_id) as sub_region,\n\t\t\t\t\t(SELECT r.slug FROM region r WHERE r.id=sub_region_id) as sub_region_slug\n\t\t\t\t\tFROM " . static::$table_name . " h\n\t\t\t\t\tWHERE 1=1 {$filter} {$text_filter}\n\t\t\t\t\t{$order_by} \n\t\t\t\t\t{$limit}"; $db->query(); $ads = array(); while ($row = mysqli_fetch_array($db->rs)) { if ($row['picture'] != '') { $picture = $upload_path . '/' . str_replace('-', '/', $row['postedon']) . '/picture/' . $row['picture']; $thumb = $upload_path . '/' . str_replace('-', '/', $row['postedon']) . '/thumb/thumb_' . $row['picture']; } else { $picture = './images/nopicture.gif'; $thumb = './images/nopicture.gif'; } $row['picture'] = $picture; $row['thumb'] = $thumb; $row['pricec'] = str_to_currency($row['price']); $row['weblink'] = create_web_link($row['webpage'], '_blank'); $row['emailto'] = create_mail_link($row['email']); $ads[] = $row; } return $ads; }
echo $qry; ?> "><?php echo $row['title']; ?> </a></h3> <p><?php echo substr($row['description'], 0, 150); ?> <a href="ad.php?<?php echo $qry; ?> ">[...]</a></p> <p><?php if ($row['price'] != '') { print str_to_currency($row['price']); } ?> </p> <p><a href="ad.php?<?php echo $qry; ?> ">More >></a></p> </div> </div> <br class='clear' /> <hr class='separator' /> <?endforeach?>