hello, how i can make a static previews to image?
i have images with tags for it (and some images without tags), i made a previews for them, but it dynamic previews, they withdraw from database by random. How it works: i take tags then withdraw all images with that tags from db and take a random row then in that row i take id of image and by that id a have a preview. How can a make a static previews select from database??
Do you have any code at the moment? Could create a materialized table view if you want it to be consistent for a certain time frame and reduce SQL load.
$latest_tag_query = mysql_query("SELECT `id_tag` FROM `tagsforimg` WHERE `id_image`=current image id); //tags for image
for ($preview_count = 1; $t = mysql_fetch_assoc($latest_tag_query); ++$preview_count){
$latest_tag_id[$preview_count]= $t['tag_id']; }
$latest_num_rows = mysql_num_rows($latest_tag_query); $preview_exist = 1; while ($preview_exist <= $latest_num_rows){ $preview_tags[$exist] .= $latest_tag_id[$preview_exist]; if($latest_num_rows - $preview_exist > 0) $preview_tags[$exist] .= ", "; $preview_exist++; } // we made a string like "tag, tag, tag"
$preview_query[$exist] = mysql_query("SELECT `id_image` FROM `tagsforimg` WHERE `id_tag` IN (".$preview_tags[$exist].") AND `id_image`!=current image id"); // we select all ids of images with that tags.
for ($pr_q_c = 1; $pr_mfa = mysql_fetch_array($preview_query[$exist]); ++$pr_q_c){
$pr_src_1[$exist] = mysql_query("SELECT `url` FROM `images` WHERE `id`=".$pr_ph_id[$exist][$pr_rand_1[$exist]].""); $pr_src_2[$exist] = mysql_query("SELECT `url` FROM `images` WHERE `id`=".$pr_ph_id[$exist][$pr_rand_2[$exist]].""); $pr_src_3[$exist] = mysql_query("SELECT `url` FROM `images` WHERE `id`=".$pr_ph_id[$exist][$pr_rand_3[$exist]].""); $pr_src_4[$exist] = mysql_query("SELECT `url` FROM `images` WHERE `id`=".$pr_ph_id[$exist][$pr_rand_4[$exist]]."");
sorry if i made some mistake with "{" and "}" , i remove some parts from it.
Bookmarks