Forum Moderators: coopster

Message Too Old, No Replies

splitting mysql query results with php

         

m8fyu

5:45 pm on Jun 18, 2011 (gmt 0)

10+ Year Member



Hi
I've been trying to figure out a way to display my query result nicely.
Basically I have a megamenu that deals with my listed items and displays them neatly in columns by creating a new unordered list per column. This particular query returns over 100 results so I'd like to start a new list when each row has 10 items. I'm using the help of some online tutes but nothing seems to work for me. I think it may be as I have nested queries.
I'm learnign from working with an existing framework and just modifying it here and there wherever I can. This uses objects, which I'm not very familiar with at all. I'm still at a basic level but with a little sweat and hard work I'm gradually getting there. However, on this occassion, I'm just about out of ideas so any helpful advice would be greatly appreciated.

My code is:

$str.="<div class=\"sub\">\n";
$str.="<ul>\n";
//get all countries
$qry="SELECT * FROM zt_locations WHERE active=1 AND parent_id IN (".$this->find_region().") ORDER BY name ASC";
$this->_parent->db->readx($qry);
$rc=$this->_parent->db->resultcount();
$data=$this->_parent->db->data;

if($rc > 0) {
for($i=0;$i<$rc;$i++){
$sublocs=$this->FindSub($data[$i]['id']); //find subloc of location of each record

$str.="<li><h2>{jump liveaboard-description&boatid=".$data[$i]['id']."}";
$str.="".$data[$i]['name']."{endjump}</h2></li>\n";

if(!empty($sublocs)) {
$sublocs="'".$data[$i]['id']."', ".$sublocs;
}else{
$sublocs="'".$data[$i]['id']."' ";
}

//$str.=$sublocs;

$qry3="SELECT * FROM zt_vessels WHERE fk_location_id IN (".$sublocs.") ORDER BY name ASC";
$this->_parent->db->readx($qry3);
$rc3=$this->_parent->db->resultcount();
$data3=$this->_parent->db->data;

if($rc3>0) {
for($m=0;$m<$rc3;$m++) {
$str.="<li>{jump liveaboard-description&boatid=".$data3[$m]['id']."}-&nbsp;";
$str.=$data3[$m]['name']; //VESSEL NAME
$str.="{endjump}</li>";
}
}
}
}
$str.="</ul>\n";
$str.="</div>\n"; //sub

m8fyu

5:53 pm on Jun 19, 2011 (gmt 0)

10+ Year Member



Pls ignore this post as I have resolved my issue. Its surprising what a good nights sleep can do for a tired brain. All I had to do was set up a new var to count each result. duh.

coopster

12:47 pm on Jun 20, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



We've all been there my friend, glad you got it sorted :)