Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Pomoc oko RandomImage

[es] :: PHP :: Pomoc oko RandomImage

[ Pregleda: 941 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

zlatko76
zlatko nikolic
srbija

Član broj: 68838
Poruke: 6
*.dynamic.isp.telekom.rs.



+1 Profil

icon Pomoc oko RandomImage10.04.2011. u 23:26 - pre 159 meseci
Radio sam jedan sajt skoro za auto oglase i na pocetnoj stranici imam najnovije oglase koji izlaze tako cim se ubaci novi oglas on se pojavi kao "newest" druga stavka je da imam na istoj stranici i random top oglase koji bi trebalo da se nasumice menjaju svaki put kad se ucita stranica, problem je sto ne mogu (umem) da napravim da rade obe funkcije istovremeno! Da li neko moze da mi ponudi resenje, stavio sam ispod ovog teksta kod funkcije, ako neko zna neka da neku sugestiju ili resenje? Unapred hvala

Code:
function getRandomImage()
{
global $use_listing_approval;
global $random_image_limit;
$limit = $random_image_limit;
$approved = '';

if ($use_listing_approval) {
if (!isset($_SESSION["admin"])) {
if (isset($_SESSION["seller"])) {
$approved = "";
} else {
$approved = "listings.approved = 1 AND listimages.approved = 1 AND ";
}
}
}

//get max id for list images so we can get random images
$sql = "SELECT COUNT(id) FROM listimages";
$max_res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
$row = sqlFetchRow($max_res);

//check if the results are less than the initial $limit if so
//set the limit to the results
if ($row['0'] < $limit) {
$limit = $row['0'];
}

$returned_ids = array();
//get the id for the list images as long as it passes our checks
$sql = "SELECT listimages.listingid FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listimages.mainimage = 1 AND listings.sold != 1";
$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());

while ($id_res = sqlFetchArray($res)) {
$returned_ids[] = $id_res["listingid"];
}

//check if the results are less than the initial $limit if so
//set the limit to the results
if (count($returned_ids) < $limit) {
$limit = count($returned_ids);
}

//if we have results set the rand var else return false
$random_id_keys = array();
if ($returned_ids) {
$random_id_keys = array_rand($returned_ids, $limit);

$c=0;
foreach ($returned_ids as $key => $value) {
if (is_array($random_id_keys)) {
if (in_array($key, $random_id_keys, TRUE)) {
//print "$key => $value<br />";
$random_ids[] = "$value";
++$c;
}
if ($c == $limit) break;
} else {
return false;
}
}

$rand = implode(',', $random_ids);
//print "<br />$rand";
} else {
return false;
}

//random id checks are succesfull do a query
//$sql = "SELECT * FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listings.sold !=1 AND listimages.mainimage = 1 ORDER BY RAND() LIMIT $limit";
$sql = "SELECT * FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listings.sold !=1 AND listimages.mainimage = 1 ORDER BY added_on DESC LIMIT $limit";
$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());

$c=0;
while ($a_row = sqlFetchArray($res)) {
$records[$c]["ad_title"] = $a_row["ad_title"];
$records[$c]["make"] = $a_row["make"];
$records[$c]["model"] = $a_row["model"];
$records[$c]["listingid"] = $a_row["listingid"];
$records[$c]["imagepath"] = $a_row["imagepath"];
$records[$c]["imagethumbpath"] = $a_row["imagethumbpath"];
$records[$c]["price"] = $a_row["price"];
$records[$c]["year"] = $a_row["year"];
++$c;
}
if (isset($records))
return $records;
return false;
}



index.tpl
Code:
{foreach item="image" from=$records}
<p>
{if $use_fancy_urls}
<a onmouseover="Tip('{$image.make}&nbsp;{$image.model}&nbsp;{$image.year}&nbsp;{$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}&#8364;')" onmouseout="UnTip()" href="listings/view/{$image.make|strip:"-"}/{$image.model|strip:"-"}/{$image.listingid}/"><img src="{$image.imagethumbpath}" title="" alt="" /></a>
{else}
<a onmouseover="Tip('{$image.make}&nbsp;{$image.model}&nbsp;{$image.year}&nbsp;{$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}&#8364;')" onmouseout="UnTip()" href="listings.php?make={$image.make|strip:"-"}&amp;model={$image.model|strip:"-"}&amp;id={$image.listingid}"><img src="{$image.imagethumbpath}" title="" alt="" /></a>
{/if}
<br /><span style="font-weight:bold;">{$image.make}&nbsp;{$image.model}&nbsp;</span><span style="color: #0000FF; font-weight: bold;"><br />{$image.year}</span>&nbsp;<span style="color: #FFFFFF; background-color: #CE1618;font-weight: bold;">&nbsp;{$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}&#8364;&nbsp;</span>
</p>
{/foreach}
</div>



index.php
Code:
<? php
require_once './Includes/configs/functions.php';
require_once './Includes/libs/Smarty.class.php';

if (file_exists("./Includes/language/$site_lang/global.php")) {
include_once "./Includes/language/$site_lang/global.php";
} else {
include_once "./Includes/language/en/global.php";
}
if (file_exists("./Includes/language/$site_lang/".basename(__FILE__)."")) {
include_once "./Includes/language/$site_lang/".basename(__FILE__)."";
}

$smarty = new Smarty;
$smarty->force_compile = $force_compile_enabled;

$file = basename(__FILE__, ".php");
if (file_exists("templates/$template/$file.tpl")) {
$smarty->template_dir="templates/$template";
} else {
$smarty->template_dir="templates/Default";
}
//$smarty->template_dir="templates/$template";

$smarty->assign("manufacturerslist",getSearchList("make"));
$smarty->assign("modelslist",getSearchList("model"));
$smarty->assign("typeslist",getSearchList("vehicle_type"));
$smarty->assign("sellerslist",getSellers());
$smarty->assign("total_vehicle_count_sold",getTotalVehicleCount('sold'));
$smarty->assign("total_vehicle_count",getTotalVehicleCount('active'));
$smarty->assign("vehicle_count_stats",getVehicleCountStats());
//$smarty->assign("conditionslist",getSearchList("listing_condition"));

//Check if single user mode 1 or multi-user mode 0
if ($site_mode == 0) {
$smarty->assign("site_mode",1);
}
//The user is already logged in.
if (isset($_SESSION["logged_in"])){
$smarty->assign("logged_in",1);
//check privs to find out if user
//is a seller, admin or user
$status = checkPrivs();
$smarty->assign("$status",1);
}

if ($use_fancy_urls) {
$smarty->assign("use_fancy_urls",1);
}

//get random images for the frontpage
$smarty->assign("records",getRandomImage());

$smarty->assign("index",1);
$smarty->display('index.tpl');
?>

zlatko nikolic
 
Odgovor na temu

[es] :: PHP :: Pomoc oko RandomImage

[ Pregleda: 941 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.