[eluser]srpurdy[/eluser]
Hi,
This might be a stupid question, but I thought I would ask. Basically I'm building an Application that has requirements of using multiple categories, which can be a different amount as much as 10 or more. So I'm using serialize() and unserialize() to display the proper entries in the proper categories.
This isn't such a big problem it works, but I haven't been able to figure out how I can do this with a low query usage. Which concerns me a little as the database could be quite large later on. Large enough that the amount of queries generated is pretty high.
So basically my question is
Is there a way to unserialize an entire mysql query result. Instead of doing it by row() like I said it's probably a stupid question, but I don't know so thought I'd ask.
Basically below to me seems very inefficient. Does anyone have a better solution. This will basically generate a query per database entry, and it's just ridiculous to me....
Sorry I cringe also when I look at this lol.
Code:
<?php foreach($query->result() as $id ) : ?>
<?$this->db->order_by("date", "desc");?>
<?$this->db->where('is_segment', 'Y');?>
<?$get_row = $this->db->get('videos');?>
<?$row2 = $get_row->row();?>
<?$get_tags = $row2->tags;?>
<?$tags = unserialize($get_tags);?>
<?php foreach($get_row->result() as $r):?>
<?#CHECK IF DATA EXIST IN THE TAGS FIELD?>
<?php if(!$r->tags == ''):?>
<?
# IF DATA DOES EXIST, UNSERIALIZE
$this->db->order_by("date", "desc");
$this->db->where('id', $r->id);
$this->db->where('is_segment', 'Y');
$new_row = $this->db->get('videos');
$row2 = $new_row->row();
$get_tags = $row2->tags;
@$tags = unserialize($get_tags);
?>
<?# DO A FOR COUNT LOOP OVER ARRAY,?>
<?php for($i = 0; $i < count($tags); $i++) : ?>
<?$uri = $this->uri->segment(3)?>
<?# COMPARE ARRAY VALUE WITH URI SEGMENT?>
<?php if(url_title($tags[$i]) == $uri):?>
<?php foreach($new_row->result() as $pv):?>
<?php if($pv->is_segment == 'Y'):?>
<div class="video">
<h4><?=htmlspecialchars($pv->name, ENT_COMPAT, 'UTF-8');?><a >id?>/<?=$pv->time_index?>/<?=$this->uri->segment(3);?>"><img style="float: right; margin-top: -3px;" src="<?=base_url();?>themes/isr_2011/img/watch.png" alt="Watch" /></a></h4>
<div class="video_content"><img >pic?>" alt="" align="left" style="padding: 5px;" /><?=$pv->desc?></div>
</div>
<?php endif;?>
<?php endforeach;?>
<?php endif;?>
<?php endfor;?>
<?php endif;?>
<?php endforeach;?>
<?php break;?>
<?php endforeach; ?>