Ninjakreborn Posted November 24, 2006 Share Posted November 24, 2006 Ok in the database I have a lot of fields.There are a lot of misc one's, which I have handled already.There are however 2 groups of associated dataactiontakenclassificationThey are named in the database with the prefix before hand like everything related to action taken is namedactiontaken_variableactiontaken_variableinside the database that is the name of the fields, the values themselves are either filled in with the same name, or they are blankFor instanceactiontaken_fellactiontaken_ranactiontaken_walkedthe values arefell, ran, and walkted respectively, but if they were not entered, then they are just blank.I need to go into the database, under a field, for instance id #1, I search that up, I display all my info, but when I get to this set of data, I need to pull everything with actiontaken_ at the beginning of the field name, I need to be able to then display it in a comma delimited list on the page showing what actions where taken, the same for classifications, I was using this they were in an array called$_SESSION['temp']['actiontaken']all the variable/value pairs were in that array, and I did the list like this[code]<?phpif (isset($_SESSION['temp']['actiontaken'])) { foreach($_SESSION['temp']['actiontaken'] as $val1) { echo $val1 . ", "; }}else { echo "None";}?>[/code]With this it took them allnow I am not sure how to do the same thing just pull them from teh database, I need to know which one's were filled out, and elave hte one's that are blank alone, or d on't show them when it comes up.I can't figure out a way, with classifications, since it was a lot more, and more advanced, I used[code]<?phpecho "<td class=\"leftcol\"><strong>Classification(s):</strong></td>\n<td class=\"rightcol\">";echo implode(", ", $_SESSION['temp']['classification']);?>[/code]This is what I did to get the same result, just doing it a different way, well all 52 fields of classification are also int eh database, in the same manner, they have a classification_ before each nameso it's field namesclassification_name1classification_name2classification_name3so for instance if name 1 and 2 were filled out then on the display page, I need it to come back and showname1, name2but I am not able to figure out how to get this functionality with a database, any advice? Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/ Share on other sites More sharing options...
Ninjakreborn Posted November 24, 2006 Author Share Posted November 24, 2006 Do I have to manually pull each and every one out of the database, and into an array manually. That will take forever though, is there another way, I was just think, I could sit there for 2 hour's, taking each variable, testing if it's blank or not, and putting it into a large array,a dn once it's acquired just doing it like I did before.Because I have to do this on 2 instances, one for them being able to edit data and one for them being able to view the data (the comma list) Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129719 Share on other sites More sharing options...
Barand Posted November 24, 2006 Share Posted November 24, 2006 I don't know how, but in the 2 years you've been studying SQL, you managed somehow to miss completely the chapter on data normalization. Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129726 Share on other sites More sharing options...
Ninjakreborn Posted November 24, 2006 Author Share Posted November 24, 2006 each table i have uses an idI know about id's, and how to associate them and all of that if that's what you mean.THis situation however is a little different, I am basing them off a list, so they are preset, it's a list of checkboxs, I am finding out which one's where checked and which one's were not, so I ended up using name/value's pair, even fenway said this is the best choice here, so I saved them.I saved them like that, they database just in the main table, under value pairs, I have them in the same table, because I didn't know how to construct a table of pre-made pairs.The one's for action taken are[quote]Aborted TakeoffCancelled FlightDeclared EmergencyDelayed FlightDiversionGo AroundGround Aircraft at OutstationInflight ShutdownMissed ApproachReturn Aircraft to MaintenanceReturn to GateTurnback[/quote]The one's for classification are[quote]Aircraft DamageAircraft on Runway"Aircraft Logs / Manuals / PhaseMissing, incomplete, inaccurate"Airport ClosureAlternator FailureATC DelayAvionics FailureCommunicationNavigationBatteryBird StrikeBrake FailureCollision (with aircraft or object)Crew IncapacitationDebris on RunwayDeviation of ATC InstructionsDisruptive / Sick PassengerDoor WarningDoor OpeningElectrical FailureEmergency EvacuationEngine FailureEngine FireFire / Smoke in CabinFlap FailureFlat TireFlight Control FailureFuel LeakFuel QuantityHard LandingIcingInstrument FailureFlight InstrumentEngine InstrumentLanding GearBlow DownFail to ExtendFail to RetractHydraulic LeakHydraulic System FailureIndication FailureLightening StrikeMagneto (failed or rough)Near Mid-Air CollissionPax InjuryProp StrikeRough EngineRunway IncursionStarter (failure or warning)Tail StrikeTurbulenceVacuum FailureWake TurbulenceWeather Below MinimumsWeather Below High MinimumsWeight and BalanceWind ShearOther[/quote]This is the list of action taken, and classification.There are a bunch of checkboxes, if they are selected they are recorded in a session array, if not they are left blank. later they are databased, I need the same thing later though, I need to extract hem, I named them in the database as actiontaken_ and classification_however it's the same thing even having them in the same other than different, if they were in a different table then it would still be the same fields. Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129728 Share on other sites More sharing options...
trq Posted November 24, 2006 Share Posted November 24, 2006 [quote]it's the same thing even having them in the same other than different[/quote]What the? Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129741 Share on other sites More sharing options...
Ninjakreborn Posted November 24, 2006 Author Share Posted November 24, 2006 Sorry I was in a hurry, it's the same thing whether i had them in another table, or in the same one.However I tried it with actiontaken, I just put them all in an array, and did this[code]<?php$actiontaken = array($row['actiontaken_abortedtakeoff'], $row['actiontaken_canceledflight'], $row['actiontaken_declaredemergency'], $row['actiontaken_delayedflight'], $row['actiontaken_diversion'], $row['actiontaken_goaround'], $row['actiontaken_groundaircraftatoutstation'], $row['actiontaken_inflightshutdown'], $row['actiontaken_missedapproach'], $row['actiontaken_returnaircrafttomaintenance'], $row['actiontaken_returntogate'], $row['actiontaken_turnback']);foreach ($actiontaken as $val1) { if ($val1 != "") { echo ", " .$val1; }}?>[/code]It work's except for one problem.THe comma is either at the beginning, or at the end of the last, or first.If there is only one then there is still, wordit's a little unprofessional, so I was playing with it, to figure out how and only append the comma "after" the first one, but only if there are other one's after it, and to stop a comma at the last one, so there isn't a beginning or trailing comma.Other than that one thing it works great, and I can do the same idea when I need to start saving them all within a session, it'll be a little more tricky but it should work out well, when I need to feed it back to the creation form for editing. Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129787 Share on other sites More sharing options...
AndyB Posted November 24, 2006 Share Posted November 24, 2006 Don't use echo ", " .$val1;Instead, concatenate a string made of $val1 plus a comma and a space. When you exit the loop, strip the last two characters (always a comma and a space) using substr(), then echo the string. Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129798 Share on other sites More sharing options...
Ninjakreborn Posted November 24, 2006 Author Share Posted November 24, 2006 [code]<?phpforeach ($actiontaken as $val1) { if ($val1 != "") { $val1 = $val1 . ", "; }}?>[/code]\Ok I formed both set's of arrays, classification and actiontaken.Not that big of a deal, easy to update later, and finished.Now, I went ahead and did a few feature based things, and ran back into this, so I looked at your post, and got your advice, but I had a few questions.Here is the first part, which was simple.I have used substr() before, but It was only for a few things and that was when working with url'sTHis time around, I needed to (as you said) strip off the last 2 characters, the , and the space after itI was wondering how to do that, or a pointer, I was thinknig substr() as you said, but it wouldnt' work would it, It only accepts 3 characters and 2 are numbered characters.I wouldn't be able to tell it where, but I was thinking regular expressions instead (unless there is something about substr() i don't know. BUt regular expressions would be aggravating for this, so then I thought about split, would there be any problems with using split, but then again it would try to find every occurence, I don't know how to go about that part. Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129819 Share on other sites More sharing options...
AndyB Posted November 25, 2006 Share Posted November 25, 2006 substr() - look at the examples near the top of the page.$rest = substr("abcdef", 0, -1); // returns "abcde"I'll leave the rest up to you. Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129844 Share on other sites More sharing options...
Ninjakreborn Posted November 25, 2006 Author Share Posted November 25, 2006 Ah perfect, thanks, I will post it back here so I won't forget monday when I start working agian, adn I can modify it then. It won't work like this, but I can keep the idea in my head on monday, the post will always be here.Quote - to help me rememberUse the code $substr($array, 0, -2);to strip the last 2 letters off of an array string. Link to comment https://forums.phpfreaks.com/topic/28362-extract-info-from-db-in-array-with-specific-name/#findComment-129845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.