28, May 2012

categories and items - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: categories and items
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: categories and items  (Read 973 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« on: Aug 26, 2006, 05:49:45 pm »

i have never worked with items that use categories Tongue 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."&amp;completed=yes&amp;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


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Aug 26, 2006, 06:07:45 pm »

I am not sure if I understand what you want, but the logic is like this :

SELECT all root categories

While result = ......

          select subcategories

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
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


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
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)

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #4 on: Aug 26, 2006, 06:14:33 pm »

hmm not sure *exactly* what you mean here.. but this is what i changed:

cat query and cat data array moved inside the while statement

Code:
<?php
//if (!isset($step)) $step = "";
echo "<center>";

$result dbquery("SELECT * FROM fusion_things2do WHERE thing_cat = $cat_id");
while (
$data dbarray($result)){
$result2 dbquery("SELECT * FROM fusion_things2do_cats ORDER BY cat_id");
$data2 dbarray($result2);
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."&amp;completed=yes&amp;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>";
?>



Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #5 on: Aug 26, 2006, 06:25:22 pm »

I think it is reverse.

You should query all the categories, and then get the items for each category (item_category = $catID or something like that )

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #6 on: Aug 26, 2006, 06:29:38 pm »

if it was reverse it would be what i had in the first place lol *is very confused*


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
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
   
}
}

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #8 on: Aug 26, 2006, 06:41:04 pm »

eek now im getting 3 blank responses from the database

Quote
.
Item Category:


[Mark As Completed]

--------------------------------------------------------------------------------

.
Item Category:


[Mark As Completed]

--------------------------------------------------------------------------------

.
Item Category:


[Mark As Completed]

--------------------------------------------------------------------------------

Code:
<?php
//if (!isset($step)) $step = "";
echo "<center>";

$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 ))
   {
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."&amp;completed=yes&amp;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>";
?>


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #9 on: Aug 26, 2006, 06:48:20 pm »

The queries are correct.

Maybe the fusion_things2do table is empty or has incorect values.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #10 on: Aug 26, 2006, 06:50:59 pm »

nope they are not empty, there is 3 items there


Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #11 on: Aug 26, 2006, 06:52:47 pm »

Do they have equal values regarding the category ids? (thing_cat, cat_id)

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
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" Tongue

Code:
<?php
//if (!isset($step)) $step = "";
echo "<center>";

$result2 dbquery("SELECT * FROM fusion_things2do_cats ORDER BY cat_id");
while (
$data2 dbarray($result2))
{
   
$result dbquery("SELECT * FROM fusion_things2do WHERE thing_cat = " $data2['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."&amp;completed=yes&amp;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>";
?>



Last blog : phpHaze 1.59.1 in Development
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
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? Tongue )

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? Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #14 on: Aug 26, 2006, 07:10:44 pm »

oh.. wow.. i didnt know that lol , yes that is good to know.. from now on i will convert my echo statements to ' instead of "


Last blog : phpHaze 1.59.1 in Development
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=3837
Tags : php Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: categories and items
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 03:27:03 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.