Jumpy09 Posted May 9, 2010 Share Posted May 9, 2010 Alright so I am setting up a progression report, but my problem is that each item has three different categories. Main Cat - Sub Cat 1 - Sub Cat 2 - Item - Item For example. User Level Pages - Profiles - Profile - Birthday Scripts (*Set up birthdays, birthday alerts, and age difference*) - User Information (*Set up mySQL queries to display all information supplied by the user. - Profile Settings - Set up Date Drop Down List - Code Form to allow users to edit profiles. - Code MySQL Queries to draw information already stored. - Code updateprofile.php to post new/updated information in the database. Here is my current script: <?php $completed = "1"; $database; $q = "SELECT * FROM progress WHERE datecompleted = '$completed'"; $result = mysql_query($q) or die(mysql_error()); $num = mysql_numrows($result); $i=0; while ($i < $num) { $pid=mysql_result($result,$i,"pid"); $item=mysql_result($result,$i,"item"); $maincat=mysql_result($result,$i,"maincat"); $subcat1=mysql_result($result,$i,"subcat1"); $subcat2=mysql_result($result,$i,"subcat2"); $info=mysql_result($result,$i,"info"); $level=mysql_result($result,$i,"level"); $datecompleted=mysql_result($result,$i,"datecompleted"); $mcat1 = mysql_query("SELECT maincat FROM progress echo " <table width=\"100%\">"; echo " <tr><th colspan=\"3\">Completed Progression / Already Tested</th></tr>"; echo " <tr><td class=\"left\" colspan=\"3\">$maincat</td></tr>"; echo " <tr><td class=\"left\">$subcat1</td><td class=\"left\" colspan=\"2\">Category Info</td>"; echo " <tr><td class=\"left\">$subcat2</td><td class=\"left\" colspan=\"2\">Sub Category Info</td>"; echo " <tr><td class=\"left\" width=\"20%\">$item</td><td class=\"left\" width=\"50%\">$iteminfo</td><td class=\"left\" width=\"30%\">$level</td>"; echo " </table>"; $i++; } It's not pretty, but I'm currently having an issue trying to find a Query which will first Post the Main Category and Info, Then the Sub Category and Info, Then All Subs of the Sub and Info, Then the Item, Item Info, Item Date Completed, and Item Level (**This is going to be a pain in the butt **) Is there any easy way to code in a small section which will take for instance: The table field "itemlevel" goes from 1 to 10. Depending on the number there, the php will generate those number of images to display completion. Then on the other side deduct that number from 10 and display the remaining in a non-completed image. Let's use red and green bars for example. Ilevel = 4. 4 Green Images are shown and then 6 Red Images are shown. Images of course would be determined by me, and small enough. Something like. IF $itemlevel == "0"; { echo '<img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img">'; } ELSEIF $itemlevel == "1"; { echo '<img src="complete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img"><img src="incomplete.img">'; } That's an example, is there any easier way to do this? How can I turn it into a Function, to save on code. For the Finale, This incorporates both PHP and MySQL, so I have absolutely no idea where to place it. Since it mostly involves PHP, that is where I put it. I hope I'm starting to get how this stuff works. It not, please let me know so I can correct it. I just wrote the image section up, it's prone to some errors.. but feel free to point them out. Thanks in Advance! Wish there was a Rep System on here to give you guys. Link to comment https://forums.phpfreaks.com/topic/201185-setting-up-a-progression-report/ Share on other sites More sharing options...
Jumpy09 Posted May 10, 2010 Author Share Posted May 10, 2010 Alright so I've been working for quite some time, after adding 6 other pages just to get this part done... I finally got it to work... in the sense it works now. <?php error_reporting (E_ALL); $completed = "1"; $database; $q = "SELECT * FROM progress WHERE completed = '$completed' ORDER BY `maincat` ASC, `subcat1` ASC,`subcat2` ASC"; $result = mysql_query($q) or die(mysql_error()); $num = mysql_numrows($result); $i=0; echo " <table width=\"100%\">"; echo " <tr><th colspan=\"3\">Completed Progression / Already Tested</th></tr>"; while ($i < $num) { $pid=mysql_result($result,$i,"pid"); $maincat=mysql_result($result,$i,"maincat"); $maincatinfo=mysql_result($result,$i,"maincatinfo"); $subcat1=mysql_result($result,$i,"subcat1"); $subcat1info=mysql_result($result,$i,"subcat1info"); $subcat2=mysql_result($result,$i,"subcat2"); $subcat2info=mysql_result($result,$i,"subcat2info"); $item=mysql_result($result,$i,"item"); $iteminfo=mysql_result($result,$i,"iteminfo"); $level=mysql_result($result,$i,"level"); $datestarted=mysql_result($result,$i,"datestarted"); $datecompleted=mysql_result($result,$i,"datecompleted"); $completed=mysql_result($result,$i,"completed"); echo " <tr><td class=\"left\" colspan=\"3\">$maincat</td></tr>"; echo " <tr><td class=\"left\">$subcat1</td><td class=\"left\" colspan=\"2\">$subcat1info</td>"; echo " <tr><td class=\"left\">$subcat2</td><td class=\"left\" colspan=\"2\">$subcat2info</td>"; echo " <tr><td class=\"left\">$datestarted</td><td class=\"left\" colspan=\"2\">$datecompleted</td>"; echo " <tr><td class=\"left\" width=\"20%\">$item</td><td class=\"left\" width=\"50%\">$iteminfo</td><td class=\"left\" width=\"30%\">$level</td></tr>"; $i++; } echo " </table>"; Is there an easier way than calling multiple queries? I have an example up there, but it doesn't work that way as you can see. The Main Cat has to generate all of it's Sub Cats... which have to generate all of it's Sub Cats... which display the items so that the next Main Cat can load. I'm going to have to call query for it in a different way. q1 = maincat / info q2 = subcat1 / info q3 = subcat2 /info q4 = item / item info and all that jazz. Above looks like it would make the Below work. I wish it was as easy as the below... but ... unfortunately it isn't. Main Cat 1 - Sub Cat 1 - 1 - Sub Cat 2 - 1 - Item - 1 - Item - 2 - Sub Cat 1 - 2 - Sub Cat 2 - 2 - Item - Item Main Cat 2 - Sub Cat 1 - 3 - Sub Cat 2 - 3 - Item - 1 - Item - 2 - Sub Cat 1 - 4 - Sub Cat 2 - 4 - Item - Item I don't think that would work either. I mean if I ... well anyway I got it up.. and it semi-works. I guess I will have to just make due with what I have. If anyone could aid me into moving this closer to what I want, it would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/201185-setting-up-a-progression-report/#findComment-1055633 Share on other sites More sharing options...
Jumpy09 Posted May 10, 2010 Author Share Posted May 10, 2010 Ohkai soe! (*Light Humor for a Video on Youtube.*) I've been working on other stuff, and just about every time I go to post a new post.. I find my answer. This one is still beginning to crush me. I've been thinking though: What if I: Make multiple tables.. which I really don't want to do.. but may not have a choice. Table 1 - Progress_MainCat Table 2 - Progress_SubCat1 Table 3 - Progress_SubCat2 Table 4 - Item Information THINK THIS WOULD WORK? echo '<table>'; $database; $qmc = mysql_query("SELECT $maincat FROM progress_maincat ORDER BY `maincatname` ASC"); $mcid = mysql_result($qmc,$i,"$maincatid"); $mcname = mysql_result($qmc,$i,"$maincatname"); $mcinfo = mysql_result($qmc,$i,"$maincatinfo"); echo "<tr><td colspan=\"2\">$maincatname</td><td colspan=\"3\">$maincatinfo</td></tr>"; $qsc1 = "SELECT $subcat1 FROM progress_subcat1 WHERE maincatid = '$maincatidid ORDER BY `subcat1name` ASC"; $sc1id = mysql_result($qsc1,$i,"$subcat1id"); $sc1name = mysql_result($qsc1,$i,"$subcat1name"); $sc1info = mysql_result($qsc1,$i,"$subcat1info"); echo "<tr><td colspan=\"2\">$subcat1name</td><td>$subcat1info</td colspan=\"3\"></tr>"; $qsc2 = "SELECT $subcat2 FROM progress_subcat2 WHERE subcat1id = '$subcat1id' ORDER BY `subcat2name` ASC"; $sc2id = mysql_result($qsc2,$i,"$subcat2id"); $sc2name = mysql_result($qsc2,$i,"$subcat2name"); $sc2info = mysql_result($qsc2,$i,"$subcat2info"); echo "<tr><td colspan=\"2\">$subcat2name</td><td>$subcat2info</td colspan=\"3\"></tr>"; $qitem = "SELECT $item FROM progress_info WHERE subcat2id = '$subcat2id' and completed = '$completed' ORDER BY `itemname` ASC"; $itemid = mysql_result($qitem,$i,"$subcat2id"); $itemname = mysql_result($qitem,$i,"$subcat2name"); $datestarted = mysql_result($qitem,$i,"$subcat2info"); $datecompleted = mysql_result($qitem,$i,"$subcat2id"); $ilevel = mysql_result($qitem,$i,"$subcat2name"); echo "<tr><td>$itemname</td><td>$iteminfo</td><td>$datestarted</td><td>$datecompleted</td><td>$ilevel</td></tr></table>"; I suppose as long as I could get it on a loop, it should display everything quite nicely. Since I put in the WHERE ... hmm. Maybe. I'm use to using something like this [code=php:0]$q = "SELECT * FROM users u,profiles p WHERE u.uid=p.uid and u.uid = '$uid'"; $result = mysql_query($q) or die(mysql_error()); $num = mysql_numrows($result); $i=0; while ($i < $num) { $i++; } How would I be able to use that while? It usually works wonders when you want to keep something in a single table. Of course I could go with <p> which I may just do, if I can't figure this out. I want the item information all on a single line, nicely spaced out. That way those green images won't be so crammed up against everything else. WELL! I'm going to set up the tables in MySQL, and go to town on this. This may put a hindrance in progress item creation, but if it works... HOLY CRAPOLI! Link to comment https://forums.phpfreaks.com/topic/201185-setting-up-a-progression-report/#findComment-1055673 Share on other sites More sharing options...
Jumpy09 Posted May 10, 2010 Author Share Posted May 10, 2010 I've got to Screenshot this! AND I DID! Alright, so here is the final code: Found MANY Errors, but I wrote the first one in a hurry then created the tables. $completed = "1"; echo '<table>'; $database; $i=0; $qmc = mysql_query("SELECT * FROM progression_maincat ORDER BY `maincatname` ASC"); $mcid = mysql_result($qmc,$i,"maincatid"); $mcname = mysql_result($qmc,$i,"maincatname"); $mcinfo = mysql_result($qmc,$i,"maincatinfo"); $qsc1 = mysql_query("SELECT * FROM progression_subcat1 WHERE maincatid = '$mcid' ORDER BY `subcat1name` ASC"); $sc1id = mysql_result($qsc1,$i,"subcat1id"); $sc1name = mysql_result($qsc1,$i,"subcat1name"); $sc1info = mysql_result($qsc1,$i,"subcat1info"); $qsc2 = mysql_query("SELECT * FROM progression_subcat2 WHERE subcat1id = '$sc1id' ORDER BY `subcat2name` ASC"); $sc2id = mysql_result($qsc2,$i,"subcat2id"); $sc2name = mysql_result($qsc2,$i,"subcat2name"); $sc2info = mysql_result($qsc2,$i,"subcat2info"); $qitem = mysql_query("SELECT * FROM progression_iteminfo WHERE subcat2id = '$sc2id' AND completed = '$completed' ORDER BY `itemname` ASC"); $itemid = mysql_result($qitem,$i,"itemid"); $itemname = mysql_result($qitem,$i,"itemname"); $iteminfo = mysql_result($qitem,$i,"iteminfo"); $datestarted = mysql_result($qitem,$i,"datestarted"); $datecompleted = mysql_result($qitem,$i,"datecompleted"); $ilevel = mysql_result($qitem,$i,"ilevel"); echo "<tr><td colspan=\"2\">$mcname</td><td colspan=\"3\">$mcinfo</td></tr>"; echo "<tr><td colspan=\"2\">$sc1name</td><td>$sc1info</td colspan=\"3\"></tr>"; echo "<tr><td colspan=\"2\">$sc2name</td><td>$sc2info</td colspan=\"3\"></tr>"; echo "<tr><td>$itemname</td><td>$iteminfo</td><td>$datestarted</td><td>$datecompleted</td><td>$ilevel</td></tr></table>"; I'm amazed at myself! Never thought I would be able to pull it off! I still don't think it's doing what I want it to do, but I do think I can get it to the point where it does. The only thing I need to make sure is a loop of some sort. Can anyone help me with a loop like this? I just overloaded my brain with that code... if it loops right... it should pull all the information properly, if not I'll have to put it back the way I had it before. $num = mysql_numrows($result); $i=0; while ($i < $num) { $i++; } Thanks Me, for talking to myself! >.> Maybe we will get some company, from someone who really exists . [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/201185-setting-up-a-progression-report/#findComment-1055680 Share on other sites More sharing options...
Jumpy09 Posted May 10, 2010 Author Share Posted May 10, 2010 I NEED A LOOP! Anyone?? Honestly, I coded that big gob of horse crap.. and I can't make a simple loop! Yeah .. I know.. I suck! Link to comment https://forums.phpfreaks.com/topic/201185-setting-up-a-progression-report/#findComment-1055686 Share on other sites More sharing options...
Jumpy09 Posted May 10, 2010 Author Share Posted May 10, 2010 We do get Daily Bumps right? Well I tried to set up a loop, and it looped infinitely! With errors... that's a huge problem. So, can anyone teach me how to loop? I've looked it up but I don't know what argument I should put on this thing and where. I tried the While ($i > $num) {} thing... but $num is mysql_numrows. So... Anything? Link to comment https://forums.phpfreaks.com/topic/201185-setting-up-a-progression-report/#findComment-1056064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.