aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 886
1148 credits Members referred : 4
« on: Aug 26, 2006, 05:49:45 pm »
i have never worked with items that use categories but im trying to do this.. i have it now so i can create categories n items, but i cant get them to list the items with their correct corresponding categories, here is code for page that lists the items... anyone help me get this fixed?
Code:
<?php //if (!isset($step)) $step = ""; echo "<center>"; $result2 = dbquery("SELECT * FROM fusion_things2do_cats ORDER BY cat_id"); $data2 = dbarray($result2); $result = dbquery("SELECT * FROM fusion_things2do WHERE thing_cat = $cat_id"); while ($data = dbarray($result)){ echo $data['thing_id']; echo ". <b>".$data['thing_name']."</b><br>"; echo "<i>Item Category: ".$data2['cat_name']."</i><br>"; echo $data['thing_description']; echo "<br><br>"; if ($data['thing_status'] == 0){ echo "[<a href='".FUSION_SELF.$aidlink."&completed=yes&thing_id=".$data['thing_id']."'>Mark As Completed</a>]<br><hr width='30%'><br>"; } else { echo "<font color='yellow' weight='bold'>Item Completed.</font><br><hr width='30%'><br>"; } } echo "</center>"; ?>
let me know if u need other pages, or table structure
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 886
1148 credits Members referred : 4
« Reply #2 on: Aug 26, 2006, 06:10:44 pm »
there are items and then the category they belong to. this is 2 tables, fusion_things2do (the items themselves, they have fields: thing_id, thing_name, thing_description, thing_cat, thing_status).. then a table fusion things2do_cats (the categories, they have fields: cat_id, cat_name). i want cat_id to correspond with the item_cat
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #3 on: Aug 26, 2006, 06:12:38 pm »
Then you should first query the categories, and in the while statement (that you wll get the cat results) you will query the items (one query for each category)
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #7 on: Aug 26, 2006, 06:35:36 pm »
It should be something like :
Code:
<?php $result = dbquery("SELECT * FROM fusion_things2do_cats ORDER BY cat_id"); while ($data = dbarray($result)){ $result2 = dbquery("SELECT * FROM fusion_things2do WHERE thing_cat = " . $data['cat_id']); while ( $data2 = dbarray( $result2 )) { //Show the items for each category here } }
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 886
1148 credits Members referred : 4
« Reply #12 on: Aug 26, 2006, 06:55:08 pm »
i found the problem. some $data and $data2 were backwards and needed to be switched around, here is the new code. do you have any recommendations to clean this up or display it better or anything, "oh php guru nikolas"
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #13 on: Aug 26, 2006, 07:04:31 pm »
Hehe I am not a guru (or am I? )
Your code looks nice. A general tip that I could give you is that :
echo 'a';
is faster than
echo "a";
because the " " are parsed while ' ' are not. Of course this is an optimization that can increase speed very very little, but it is good to know, right?