Jump to content

extract info from db in array with specific name


Ninjakreborn

Recommended Posts

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 data
actiontaken
classification
They are named in the database with the prefix before hand like everything related to action taken is named
actiontaken_variable
actiontaken_variable
inside the database that is the name of the fields, the values themselves are either filled in with the same name, or they are blank
For instance
actiontaken_fell
actiontaken_ran
actiontaken_walked
the values are
fell, 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]<?php
if (isset($_SESSION['temp']['actiontaken'])) {
foreach($_SESSION['temp']['actiontaken'] as $val1) {
echo $val1 . ", ";
}
}else {
echo "None";
}
?>[/code]
With this it took them all
now 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]<?php
echo "<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 name
so it's
field names
classification_name1
classification_name2
classification_name3
so for instance if name 1 and 2 were filled out then on the display page, I need it to come back and show
name1, name2

but I am not able to figure out how to get this functionality with a database, any advice?
Link to comment
Share on other sites

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
Share on other sites

each table i have uses an id
I 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 Takeoff
Cancelled Flight
Declared Emergency
Delayed Flight
Diversion
Go Around
Ground Aircraft at Outstation
Inflight Shutdown
Missed Approach
Return Aircraft to Maintenance
Return to Gate
Turnback
[/quote]

The one's for classification are

[quote]Aircraft Damage
Aircraft on Runway
"Aircraft Logs / Manuals / Phase
Missing, incomplete, inaccurate"
Airport Closure
Alternator Failure
ATC Delay
Avionics Failure
Communication
Navigation
Battery
Bird Strike
Brake Failure
Collision (with aircraft or object)
Crew Incapacitation
Debris on Runway
Deviation of ATC Instructions
Disruptive / Sick Passenger
Door Warning
Door Opening
Electrical Failure
Emergency Evacuation
Engine Failure
Engine Fire
Fire / Smoke in Cabin
Flap Failure
Flat Tire
Flight Control Failure
Fuel Leak
Fuel Quantity
Hard Landing
Icing
Instrument Failure
Flight Instrument
Engine Instrument
Landing Gear
Blow Down
Fail to Extend
Fail to Retract
Hydraulic Leak
Hydraulic System Failure
Indication Failure
Lightening Strike
Magneto (failed or rough)
Near Mid-Air Collission
Pax Injury
Prop Strike
Rough Engine
Runway Incursion
Starter (failure or warning)
Tail Strike
Turbulence
Vacuum Failure
Wake Turbulence
Weather Below Minimums
Weather Below High Minimums
Weight and Balance
Wind Shear
Other[/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
Share on other sites

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
, word
it'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
Share on other sites

[code]<?php
foreach ($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's
THis time around, I needed to (as you said) strip off the last 2 characters, the , and the space after it
I 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
Share on other sites

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 remember
Use the code
$substr($array, 0, -2);
to strip the last 2 letters off of an array string.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.