Welcome Guest, Not a member yet? Register   Sign In
unserialize (multi category) ....
#1

[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,?>
          &lt;?php for($i = 0; $i < count($tags); $i++) : ?&gt;
          &lt;?$uri = $this->uri->segment(3)?&gt;
          &lt;?# COMPARE ARRAY VALUE WITH URI SEGMENT?&gt;
            &lt;?php if(url_title($tags[$i]) == $uri):?&gt;
              &lt;?php foreach($new_row->result() as $pv):?&gt;
        &lt;?php if($pv->is_segment == 'Y'):?&gt;
          <div class="video">
            <h4>&lt;?=htmlspecialchars($pv->name, ENT_COMPAT, 'UTF-8');?&gt;<a >id?&gt;/&lt;?=$pv->time_index?&gt;/&lt;?=$this->uri->segment(3);?&gt;"><img style="float: right; margin-top: -3px;" src="&lt;?=base_url();?&gt;themes/isr_2011/img/watch.png" alt="Watch" /></a></h4>
            <div class="video_content"><img >pic?&gt;" alt="" align="left" style="padding: 5px;" />&lt;?=$pv->desc?&gt;</div>
        </div>
        &lt;?php endif;?&gt;
              &lt;?php endforeach;?&gt;
            &lt;?php endif;?&gt;
          &lt;?php endfor;?&gt;
    &lt;?php endif;?&gt;
  &lt;?php endforeach;?&gt;
&lt;?php break;?&gt;
&lt;?php endforeach; ?&gt;
#2

[eluser]srpurdy[/eluser]
Okay I totally forgot about the mysql like()

This looks much better. Smile

1 Query instead of an exponential query of destruction Big Grin

Code:
?php foreach( $query->result() as $id ) : ?&gt;
&lt;?#GET THE VIDEO ENTRYS?&gt;
&lt;?$this->db->order_by("date", "desc");?&gt;
&lt;?$this->db->like('tags', url_title($this->uri->segment(3)));?&gt;
&lt;?$this->db->where('is_segment', 'Y');?&gt;
&lt;?$get_row = $this->db->get('videos');?&gt;
              &lt;?php foreach($get_row->result() as $pv):?&gt;
        &lt;?php if($pv->is_segment == 'Y'):?&gt;
          <div class="video">
            <h4>&lt;?=htmlspecialchars($pv->name, ENT_COMPAT, 'UTF-8');?&gt;<a >id?&gt;/&lt;?=$pv->time_index?&gt;/&lt;?=$this->uri->segment(3);?&gt;"><img style="float: right; margin-top: -3px;" src="&lt;?=base_url();?&gt;themes/isr_2011/img/watch.png" alt="Watch" /></a></h4>
            <div class="video_content"><img >pic?&gt;" alt="" align="left" style="padding: 5px;" />&lt;?=$pv->desc?&gt;</div>
        </div>
        &lt;?php endif;?&gt;
              &lt;?php endforeach;?&gt;
&lt;?php endforeach; ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB