Jump to content

Solved (thanks)2 arrays into query


Ninjakreborn

Recommended Posts

On an update query you need to do
UPDATE tablename SET whatever = 'whatever'
I have a huge query, that has 2 giant array's of equal values.
THe 2 arrays are called
$name
$value
I need to create a query that is going to do
$update = "UPDATE eventreport SET $name = '$value' WHERE id = '$id';";
ok here is the thing, This is a simple query, but by hand I would have to go in and do
$update = "UPDATE eventreport SET name = '$name', t_number = '$t-number' and so forth, it would be a lot
is there a way to make it automatically put in the
name = 'value', name2 = 'value2', name3 = 'value3
I was wanting to just put all of those in there dynamically to make the process faster?
I was thinking about a foreach statement, pretty easy, but in relation to 2 array's?
plus having to do them both
I was thinking of this, but I dont know the affects
$update = "UPDATE eventreport SET " .
foreach ($name as $tempname) {
echo $tempname;
} .
foreach ($value as $tempvalue) {
echo $tempvalue;
} .
"WHERE id = '$id';";
then that would build the query, I would have to modify it some to work, and put in the comma's but does anyone have any ideas?

actually even then it would throw out all the names, then all the values, instead of doing them together.
Link to comment
Share on other sites

Something like? (Not at all tested)

[code=php:0]
$sql = "UPDATE tbl SET ";
for ($i=0;$i<=count($names);$i++) {
  if ($i == count($names)) {
    $sql .= $names[$i]."='".$values[$i]."'";
  } else {
    $sql .= $names[$i]."='".$values[$i]."',";
  }
}
$sql .= " WHERE id = '$id';";
[/code]
Link to comment
Share on other sites

Where are the values coming from?

If they are not coming from a form, create an array that holds the names of the variables that will be used to create the query, use a temporary array, and a foreach loop to build the query:

[code]<?php
$tmpa = array('name','t_number','something');
$tmpq = array();
foreach($tmpa as $var)
    $tmpq = $var . " = '" . mysql_real_escape_string($$var) . "'";
$q = 'update eventreport set ' . implode(', ',$tmpq) . " where id = '$id'";
?>[/code]

If the variable come from a form, you can use the foreach on the $_POST array.

Ken
Link to comment
Share on other sites

They are coming from a database and form.
This is the edit portion, I pull the info from the database, register a bunch of sessions, so they are coming from sessions.
THe name's in the database are slightly different though because of mysql naming rules, I can't have - so instead they have to be - for the database, and the database is also named differently, so the name/value's are different.
I am trying out what you suggested right now.
Link to comment
Share on other sites

[quote]UPDATE tbl SET name='sadd',t_number='david',flighttype='Part 135',aircrafttype='C402',aircraftnumber='N106CA',eventdate='12/05/1983',eventtime='0900',flightnumber='west',flightnumberselect='',scheduleddepartureairport='asd',scheduledarrivalairport='asd',captain='asd',firstofficer='asd',flightattendant='asd',additionalcrewmembers='asd',weather='asd',flightplan='VFR',pax='asd',lapchildren='asd',actiontaken_abortedtakeoff='Aborted Takeoff',actiontaken_canceledflight='',actiontaken_declaredemergency='',actiontaken_delayedflight='',actiontaken_diversion='',actiontaken_goaround='',actiontaken_groundaircraftatoutstation='',actiontaken_inflightshutdown='Inflight Shutdown',actiontaken_missedapproach='',actiontaken_returnaircrafttomaintenance='',actiontaken_returntogate='',actiontaken_turnback='',phaseofflight='Deplaning',classification_aircraftdamage='Aircraft Damage',classification_aircraftonrunway='',classification_aircraftlogsmanualsorphase='',classification_airportclosure='',classification_alternatorfailure='Alternator Failure',classification_atcdelay='',classification_avionicsfailure_communication='',classification_avionicsfailure_navigation='',classification_battery='',classification_birdstrike='',classification_brakefailure='',classification_collision='',classification_crewincapacitation='',classification_debrisonrunway='',classification_deviationofatcinstructions='',classification_disruptiveorsickpassenger='',classification_doorwarning='Door Warning',classification_doorwarningwhichone='wearsa',classification_dooropening='',classification_dooropeningwhichone='',classification_electricalfailure='',classification_emergencyevacuation='',classification_enginefailure='',classification_enginefire='',classification_fireorsmokeincabin='',classification_flapfailure='',classification_flattire='',classification_flightcontrolfailure='',classification_fuelleak='',classification_fuelquantity='',classification_hardlanding='',classification_icing='',classification_flightinstrument='',classification_flightinstrumentwhich='',classification_engineinstrument='Engine Instrument',classification_engineinstrumentwhich='sdfasdf',classification_landinggear_blowdown='',classification_landinggear_failtoextend='',classification_landinggear_failtoretract='',classification_landinggear_hydraulicleak='',classification_landinggear_hydraulicsystemfailure='',classification_landinggear_falseindication='',classification_lighteningstrike='',classification_magnetofailedorrough='',classification_nearmidaircollision='',classification_paxinjury='',classification_propstrike='',classification_roughengine='',classification_runwayincursion='',classification_starterfailureorwarning='',classification_tailstrike='',classification_turbulence='',classification_vacuumfailure='',classification_waketurbulence='',classification_weatherbelowminimums='',classification_weatherbelowhighminimums='',classification_weightandbalance='',classification_windshear='Wind Shear',classification_other='Other',classification_othertext='west',description='hello',='' WHERE id = '';[/quote]
Ok this is what happened when I echod' the statement, there are a few problems if you could help, at the end it's still ,=" WHERE id so it's a little off.
Also the id isn't passing, but I can check on that in a minute, that is probably me,
any advice?>
Link to comment
Share on other sites

Sorry, i should have thought about that.

I got that query working, and took that same script and modified it to something heavier,
[code]<?php
//  build query
$names = array("name", "t_number", "flighttype", "aircrafttype", "aircraftnumber", "eventdate", "eventtime", "flightnumber", "flightnumberselect", "scheduleddepartureairport", "scheduledarrivalairport", "captain", "firstofficer", "flightattendant", "additionalcrewmembers", "weather", "flightplan", "pax", "lapchildren", "actiontaken_abortedtakeoff", "actiontaken_canceledflight", "actiontaken_declaredemergency", "actiontaken_delayedflight", "actiontaken_diversion", "actiontaken_goaround", "actiontaken_groundaircraftatoutstation", "actiontaken_inflightshutdown", "actiontaken_missedapproach", "actiontaken_returnaircrafttomaintenance", "actiontaken_returntogate", "actiontaken_turnback", "phaseofflight", "classification_aircraftdamage", "classification_aircraftonrunway", "classification_aircraftlogsmanualsorphase", "classification_airportclosure", "classification_alternatorfailure", "classification_atcdelay", "classification_avionicsfailure_communication", "classification_avionicsfailure_navigation", "classification_battery", "classification_birdstrike", "classification_brakefailure", "classification_collision", "classification_crewincapacitation", "classification_debrisonrunway", "classification_deviationofatcinstructions", "classification_disruptiveorsickpassenger", "classification_doorwarning", "classification_doorwarningwhichone", "classification_dooropening", "classification_dooropeningwhichone", "classification_electricalfailure", "classification_emergencyevacuation", "classification_enginefailure", "classification_enginefire", "classification_fireorsmokeincabin", "classification_flapfailure", "classification_flattire", "classification_flightcontrolfailure", "classification_fuelleak", "classification_fuelquantity", "classification_hardlanding", "classification_icing", "classification_flightinstrument", "classification_flightinstrumentwhich", "classification_engineinstrument", "classification_engineinstrumentwhich", "classification_landinggear_blowdown", "classification_landinggear_failtoextend", "classification_landinggear_failtoretract", "classification_landinggear_hydraulicleak", "classification_landinggear_hydraulicsystemfailure", "classification_landinggear_falseindication", "classification_lighteningstrike", "classification_magnetofailedorrough", "classification_nearmidaircollision", "classification_paxinjury", "classification_propstrike", "classification_roughengine", "classification_runwayincursion", "classification_starterfailureorwarning", "classification_tailstrike", "classification_turbulence", "classification_vacuumfailure", "classification_waketurbulence", "classification_weatherbelowminimums", "classification_weatherbelowhighminimums", "classification_weightandbalance", "classification_windshear", "classification_other", "classification_othertext", "description");
$select = "SELECT * FROM eventreport WHERE ";
for ($i=0;$i<=count($names);$i++) {
$values = mysql_real_escape_string($_POST['search1field']);
$values = "'%{$values}%'";
  if ($i == count($names)) {
    $select .= $names[$i] . " LIKE " . $values;
  } else {
    $select .= $names[$i] . " LIKE " . $values . " OR ";
  }
}
$select .= "LIMIT $rownumber, $limit;";
// end building query
?>[/code]
It's working except, it is having a syntax error at the end

[quote]SELECT * FROM eventreport WHERE name LIKE '%ad%' OR t_number LIKE '%ad%' OR flighttype LIKE '%ad%' OR aircrafttype LIKE '%ad%' OR aircraftnumber LIKE '%ad%' OR eventdate LIKE '%ad%' OR eventtime LIKE '%ad%' OR flightnumber LIKE '%ad%' OR flightnumberselect LIKE '%ad%' OR scheduleddepartureairport LIKE '%ad%' OR scheduledarrivalairport LIKE '%ad%' OR captain LIKE '%ad%' OR firstofficer LIKE '%ad%' OR flightattendant LIKE '%ad%' OR additionalcrewmembers LIKE '%ad%' OR weather LIKE '%ad%' OR flightplan LIKE '%ad%' OR pax LIKE '%ad%' OR lapchildren LIKE '%ad%' OR actiontaken_abortedtakeoff LIKE '%ad%' OR actiontaken_canceledflight LIKE '%ad%' OR actiontaken_declaredemergency LIKE '%ad%' OR actiontaken_delayedflight LIKE '%ad%' OR actiontaken_diversion LIKE '%ad%' OR actiontaken_goaround LIKE '%ad%' OR actiontaken_groundaircraftatoutstation LIKE '%ad%' OR actiontaken_inflightshutdown LIKE '%ad%' OR actiontaken_missedapproach LIKE '%ad%' OR actiontaken_returnaircrafttomaintenance LIKE '%ad%' OR actiontaken_returntogate LIKE '%ad%' OR actiontaken_turnback LIKE '%ad%' OR phaseofflight LIKE '%ad%' OR classification_aircraftdamage LIKE '%ad%' OR classification_aircraftonrunway LIKE '%ad%' OR classification_aircraftlogsmanualsorphase LIKE '%ad%' OR classification_airportclosure LIKE '%ad%' OR classification_alternatorfailure LIKE '%ad%' OR classification_atcdelay LIKE '%ad%' OR classification_avionicsfailure_communication LIKE '%ad%' OR classification_avionicsfailure_navigation LIKE '%ad%' OR classification_battery LIKE '%ad%' OR classification_birdstrike LIKE '%ad%' OR classification_brakefailure LIKE '%ad%' OR classification_collision LIKE '%ad%' OR classification_crewincapacitation LIKE '%ad%' OR classification_debrisonrunway LIKE '%ad%' OR classification_deviationofatcinstructions LIKE '%ad%' OR classification_disruptiveorsickpassenger LIKE '%ad%' OR classification_doorwarning LIKE '%ad%' OR classification_doorwarningwhichone LIKE '%ad%' OR classification_dooropening LIKE '%ad%' OR classification_dooropeningwhichone LIKE '%ad%' OR classification_electricalfailure LIKE '%ad%' OR classification_emergencyevacuation LIKE '%ad%' OR classification_enginefailure LIKE '%ad%' OR classification_enginefire LIKE '%ad%' OR classification_fireorsmokeincabin LIKE '%ad%' OR classification_flapfailure LIKE '%ad%' OR classification_flattire LIKE '%ad%' OR classification_flightcontrolfailure LIKE '%ad%' OR classification_fuelleak LIKE '%ad%' OR classification_fuelquantity LIKE '%ad%' OR classification_hardlanding LIKE '%ad%' OR classification_icing LIKE '%ad%' OR classification_flightinstrument LIKE '%ad%' OR classification_flightinstrumentwhich LIKE '%ad%' OR classification_engineinstrument LIKE '%ad%' OR classification_engineinstrumentwhich LIKE '%ad%' OR classification_landinggear_blowdown LIKE '%ad%' OR classification_landinggear_failtoextend LIKE '%ad%' OR classification_landinggear_failtoretract LIKE '%ad%' OR classification_landinggear_hydraulicleak LIKE '%ad%' OR classification_landinggear_hydraulicsystemfailure LIKE '%ad%' OR classification_landinggear_falseindication LIKE '%ad%' OR classification_lighteningstrike LIKE '%ad%' OR classification_magnetofailedorrough LIKE '%ad%' OR classification_nearmidaircollision LIKE '%ad%' OR classification_paxinjury LIKE '%ad%' OR classification_propstrike LIKE '%ad%' OR classification_roughengine LIKE '%ad%' OR classification_runwayincursion LIKE '%ad%' OR classification_starterfailureorwarning LIKE '%ad%' OR classification_tailstrike LIKE '%ad%' OR classification_turbulence LIKE '%ad%' OR classification_vacuumfailure LIKE '%ad%' OR classification_waketurbulence LIKE '%ad%' OR classification_weatherbelowminimums LIKE '%ad%' OR classification_weatherbelowhighminimums LIKE '%ad%' OR classification_weightandbalance LIKE '%ad%' OR classification_windshear LIKE '%ad%' OR classification_other LIKE '%ad%' OR classification_othertext LIKE '%ad%' OR description LIKE '%ad%' OR LIKE '%ad%'LIMIT 0, 20;[/quote]

You see at the end OR LIKE
I was trying to search my name "west" and it worked, because I had substr($select, 0, -16);
I thought that would work, but instead when I search for a 2 letter word, it came upw ith this, so that won't work, it's dependent on the size of the text.
So now what?
Link to comment
Share on other sites

Still stuck on this, for one the I is returning 94 when I echo it, but when I echo count($name)
it tell's me 93
but even if I do
[code]<?php
//  build query
$names = array("name", "t_number", "flighttype", "aircrafttype", "aircraftnumber", "eventdate", "eventtime", "flightnumber", "flightnumberselect", "scheduleddepartureairport", "scheduledarrivalairport", "captain", "firstofficer", "flightattendant", "additionalcrewmembers", "weather", "flightplan", "pax", "lapchildren", "actiontaken_abortedtakeoff", "actiontaken_canceledflight", "actiontaken_declaredemergency", "actiontaken_delayedflight", "actiontaken_diversion", "actiontaken_goaround", "actiontaken_groundaircraftatoutstation", "actiontaken_inflightshutdown", "actiontaken_missedapproach", "actiontaken_returnaircrafttomaintenance", "actiontaken_returntogate", "actiontaken_turnback", "phaseofflight", "classification_aircraftdamage", "classification_aircraftonrunway", "classification_aircraftlogsmanualsorphase", "classification_airportclosure", "classification_alternatorfailure", "classification_atcdelay", "classification_avionicsfailure_communication", "classification_avionicsfailure_navigation", "classification_battery", "classification_birdstrike", "classification_brakefailure", "classification_collision", "classification_crewincapacitation", "classification_debrisonrunway", "classification_deviationofatcinstructions", "classification_disruptiveorsickpassenger", "classification_doorwarning", "classification_doorwarningwhichone", "classification_dooropening", "classification_dooropeningwhichone", "classification_electricalfailure", "classification_emergencyevacuation", "classification_enginefailure", "classification_enginefire", "classification_fireorsmokeincabin", "classification_flapfailure", "classification_flattire", "classification_flightcontrolfailure", "classification_fuelleak", "classification_fuelquantity", "classification_hardlanding", "classification_icing", "classification_flightinstrument", "classification_flightinstrumentwhich", "classification_engineinstrument", "classification_engineinstrumentwhich", "classification_landinggear_blowdown", "classification_landinggear_failtoextend", "classification_landinggear_failtoretract", "classification_landinggear_hydraulicleak", "classification_landinggear_hydraulicsystemfailure", "classification_landinggear_falseindication", "classification_lighteningstrike", "classification_magnetofailedorrough", "classification_nearmidaircollision", "classification_paxinjury", "classification_propstrike", "classification_roughengine", "classification_runwayincursion", "classification_starterfailureorwarning", "classification_tailstrike", "classification_turbulence", "classification_vacuumfailure", "classification_waketurbulence", "classification_weatherbelowminimums", "classification_weatherbelowhighminimums", "classification_weightandbalance", "classification_windshear", "classification_other", "classification_othertext", "description");
$values = mysql_real_escape_string($_POST['search1field']);
$values = "'%{$values}%'";
$select = "SELECT * FROM eventreport WHERE ";
for ($i=0;$i<=count($names);$i++) {
  if ($i == 94) {
$select .= $names[$i] . " LIKE " . $values;
  } else {
    $select .= $names[$i] . " LIKE " . $values . " OR ";
  }
}
$select .= "LIMIT $rownumber, $limit;";
// end building query
?>[/code]
then it echo's the following (I also am echoign select a little further down.





[quote]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ninksafe/public_html/mainadmin/vieweventssearch.php on line 53
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%aszf%' OR LIMIT 0, 20' at line 1
SELECT * FROM eventreport WHERE name LIKE '%aszf%' OR t_number LIKE '%aszf%' OR flighttype LIKE '%aszf%' OR aircrafttype LIKE '%aszf%' OR aircraftnumber LIKE '%aszf%' OR eventdate LIKE '%aszf%' OR eventtime LIKE '%aszf%' OR flightnumber LIKE '%aszf%' OR flightnumberselect LIKE '%aszf%' OR scheduleddepartureairport LIKE '%aszf%' OR scheduledarrivalairport LIKE '%aszf%' OR captain LIKE '%aszf%' OR firstofficer LIKE '%aszf%' OR flightattendant LIKE '%aszf%' OR additionalcrewmembers LIKE '%aszf%' OR weather LIKE '%aszf%' OR flightplan LIKE '%aszf%' OR pax LIKE '%aszf%' OR lapchildren LIKE '%aszf%' OR actiontaken_abortedtakeoff LIKE '%aszf%' OR actiontaken_canceledflight LIKE '%aszf%' OR actiontaken_declaredemergency LIKE '%aszf%' OR actiontaken_delayedflight LIKE '%aszf%' OR actiontaken_diversion LIKE '%aszf%' OR actiontaken_goaround LIKE '%aszf%' OR actiontaken_groundaircraftatoutstation LIKE '%aszf%' OR actiontaken_inflightshutdown LIKE '%aszf%' OR actiontaken_missedapproach LIKE '%aszf%' OR actiontaken_returnaircrafttomaintenance LIKE '%aszf%' OR actiontaken_returntogate LIKE '%aszf%' OR actiontaken_turnback LIKE '%aszf%' OR phaseofflight LIKE '%aszf%' OR classification_aircraftdamage LIKE '%aszf%' OR classification_aircraftonrunway LIKE '%aszf%' OR classification_aircraftlogsmanualsorphase LIKE '%aszf%' OR classification_airportclosure LIKE '%aszf%' OR classification_alternatorfailure LIKE '%aszf%' OR classification_atcdelay LIKE '%aszf%' OR classification_avionicsfailure_communication LIKE '%aszf%' OR classification_avionicsfailure_navigation LIKE '%aszf%' OR classification_battery LIKE '%aszf%' OR classification_birdstrike LIKE '%aszf%' OR classification_brakefailure LIKE '%aszf%' OR classification_collision LIKE '%aszf%' OR classification_crewincapacitation LIKE '%aszf%' OR classification_debrisonrunway LIKE '%aszf%' OR classification_deviationofatcinstructions LIKE '%aszf%' OR classification_disruptiveorsickpassenger LIKE '%aszf%' OR classification_doorwarning LIKE '%aszf%' OR classification_doorwarningwhichone LIKE '%aszf%' OR classification_dooropening LIKE '%aszf%' OR classification_dooropeningwhichone LIKE '%aszf%' OR classification_electricalfailure LIKE '%aszf%' OR classification_emergencyevacuation LIKE '%aszf%' OR classification_enginefailure LIKE '%aszf%' OR classification_enginefire LIKE '%aszf%' OR classification_fireorsmokeincabin LIKE '%aszf%' OR classification_flapfailure LIKE '%aszf%' OR classification_flattire LIKE '%aszf%' OR classification_flightcontrolfailure LIKE '%aszf%' OR classification_fuelleak LIKE '%aszf%' OR classification_fuelquantity LIKE '%aszf%' OR classification_hardlanding LIKE '%aszf%' OR classification_icing LIKE '%aszf%' OR classification_flightinstrument LIKE '%aszf%' OR classification_flightinstrumentwhich LIKE '%aszf%' OR classification_engineinstrument LIKE '%aszf%' OR classification_engineinstrumentwhich LIKE '%aszf%' OR classification_landinggear_blowdown LIKE '%aszf%' OR classification_landinggear_failtoextend LIKE '%aszf%' OR classification_landinggear_failtoretract LIKE '%aszf%' OR classification_landinggear_hydraulicleak LIKE '%aszf%' OR classification_landinggear_hydraulicsystemfailure LIKE '%aszf%' OR classification_landinggear_falseindication LIKE '%aszf%' OR classification_lighteningstrike LIKE '%aszf%' OR classification_magnetofailedorrough LIKE '%aszf%' OR classification_nearmidaircollision LIKE '%aszf%' OR classification_paxinjury LIKE '%aszf%' OR classification_propstrike LIKE '%aszf%' OR classification_roughengine LIKE '%aszf%' OR classification_runwayincursion LIKE '%aszf%' OR classification_starterfailureorwarning LIKE '%aszf%' OR classification_tailstrike LIKE '%aszf%' OR classification_turbulence LIKE '%aszf%' OR classification_vacuumfailure LIKE '%aszf%' OR classification_waketurbulence LIKE '%aszf%' OR classification_weatherbelowminimums LIKE '%aszf%' OR classification_weatherbelowhighminimums LIKE '%aszf%' OR classification_weightandbalance LIKE '%aszf%' OR classification_windshear LIKE '%aszf%' OR classification_other LIKE '%aszf%' OR classification_othertext LIKE '%aszf%' OR description LIKE '%aszf%' OR LIKE '%aszf%' OR LIMIT 0, 20;

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ninksafe/public_html/mainadmin/vieweventssearch.php on line 59[/quote]

I have to figure out a way to fix this, I have been working with it the past 2-3 hours with no luck

Anybody?
Link to comment
Share on other sites

When I mentioned "normalization" you replied that it makes no difference whether the data is in the same table or a different one. Then you produce a code abomination like this

[quote]
SELECT * FROM eventreport WHERE name LIKE '%ad%' OR t_number LIKE '%ad%' OR flighttype LIKE '%ad%' OR aircrafttype LIKE '%ad%' OR aircraftnumber LIKE '%ad%' OR eventdate LIKE '%ad%' OR eventtime LIKE '%ad%' OR flightnumber LIKE '%ad%' OR flightnumberselect LIKE '%ad%' OR scheduleddepartureairport LIKE '%ad%' OR scheduledarrivalairport LIKE '%ad%' OR captain LIKE '%ad%' OR firstofficer LIKE '%ad%' OR flightattendant LIKE '%ad%' OR additionalcrewmembers LIKE '%ad%' OR weather LIKE '%ad%' OR flightplan LIKE '%ad%' OR pax LIKE '%ad%' OR lapchildren LIKE '%ad%' OR actiontaken_abortedtakeoff LIKE '%ad%' OR actiontaken_canceledflight LIKE '%ad%' OR actiontaken_declaredemergency LIKE '%ad%' OR actiontaken_delayedflight LIKE '%ad%' OR actiontaken_diversion LIKE '%ad%' OR actiontaken_goaround LIKE '%ad%' OR actiontaken_groundaircraftatoutstation LIKE '%ad%' OR actiontaken_inflightshutdown LIKE '%ad%' OR actiontaken_missedapproach LIKE '%ad%' OR actiontaken_returnaircrafttomaintenance LIKE '%ad%' OR actiontaken_returntogate LIKE '%ad%' OR actiontaken_turnback LIKE '%ad%' OR phaseofflight LIKE '%ad%' OR classification_aircraftdamage LIKE '%ad%' OR classification_aircraftonrunway LIKE '%ad%' OR classification_aircraftlogsmanualsorphase LIKE '%ad%' OR classification_airportclosure LIKE '%ad%' OR classification_alternatorfailure LIKE '%ad%' OR classification_atcdelay LIKE '%ad%' OR classification_avionicsfailure_communication LIKE '%ad%' OR classification_avionicsfailure_navigation LIKE '%ad%' OR classification_battery LIKE '%ad%' OR classification_birdstrike LIKE '%ad%' OR classification_brakefailure LIKE '%ad%' OR classification_collision LIKE '%ad%' OR classification_crewincapacitation LIKE '%ad%' OR classification_debrisonrunway LIKE '%ad%' OR classification_deviationofatcinstructions LIKE '%ad%' OR classification_disruptiveorsickpassenger LIKE '%ad%' OR classification_doorwarning LIKE '%ad%' OR classification_doorwarningwhichone LIKE '%ad%' OR classification_dooropening LIKE '%ad%' OR classification_dooropeningwhichone LIKE '%ad%' OR classification_electricalfailure LIKE '%ad%' OR classification_emergencyevacuation LIKE '%ad%' OR classification_enginefailure LIKE '%ad%' OR classification_enginefire LIKE '%ad%' OR classification_fireorsmokeincabin LIKE '%ad%' OR classification_flapfailure LIKE '%ad%' OR classification_flattire LIKE '%ad%' OR classification_flightcontrolfailure LIKE '%ad%' OR classification_fuelleak LIKE '%ad%' OR classification_fuelquantity LIKE '%ad%' OR classification_hardlanding LIKE '%ad%' OR classification_icing LIKE '%ad%' OR classification_flightinstrument LIKE '%ad%' OR classification_flightinstrumentwhich LIKE '%ad%' OR classification_engineinstrument LIKE '%ad%' OR classification_engineinstrumentwhich LIKE '%ad%' OR classification_landinggear_blowdown LIKE '%ad%' OR classification_landinggear_failtoextend LIKE '%ad%' OR classification_landinggear_failtoretract LIKE '%ad%' OR classification_landinggear_hydraulicleak LIKE '%ad%' OR classification_landinggear_hydraulicsystemfailure LIKE '%ad%' OR classification_landinggear_falseindication LIKE '%ad%' OR classification_lighteningstrike LIKE '%ad%' OR classification_magnetofailedorrough LIKE '%ad%' OR classification_nearmidaircollision LIKE '%ad%' OR classification_paxinjury LIKE '%ad%' OR classification_propstrike LIKE '%ad%' OR classification_roughengine LIKE '%ad%' OR classification_runwayincursion LIKE '%ad%' OR classification_starterfailureorwarning LIKE '%ad%' OR classification_tailstrike LIKE '%ad%' OR classification_turbulence LIKE '%ad%' OR classification_vacuumfailure LIKE '%ad%' OR classification_waketurbulence LIKE '%ad%' OR classification_weatherbelowminimums LIKE '%ad%' OR classification_weatherbelowhighminimums LIKE '%ad%' OR classification_weightandbalance LIKE '%ad%' OR classification_windshear LIKE '%ad%' OR classification_other LIKE '%ad%' OR classification_othertext LIKE '%ad%' OR description LIKE '%ad%' OR LIKE '%ad%'LIMIT 0, 20;[/quote]

I rest my case.
Link to comment
Share on other sites

I would it like this...

[code]<?php

//  build query

$names = array("name", "t_number", "flighttype", "aircrafttype", "aircraftnumber", "eventdate", "eventtime", "flightnumber", "flightnumberselect", "scheduleddepartureairport", "scheduledarrivalairport", "captain", "firstofficer", "flightattendant", "additionalcrewmembers", "weather", "flightplan", "pax", "lapchildren", "actiontaken_abortedtakeoff", "actiontaken_canceledflight", "actiontaken_declaredemergency", "actiontaken_delayedflight", "actiontaken_diversion", "actiontaken_goaround", "actiontaken_groundaircraftatoutstation", "actiontaken_inflightshutdown", "actiontaken_missedapproach", "actiontaken_returnaircrafttomaintenance", "actiontaken_returntogate", "actiontaken_turnback", "phaseofflight", "classification_aircraftdamage", "classification_aircraftonrunway", "classification_aircraftlogsmanualsorphase", "classification_airportclosure", "classification_alternatorfailure", "classification_atcdelay", "classification_avionicsfailure_communication", "classification_avionicsfailure_navigation", "classification_battery", "classification_birdstrike", "classification_brakefailure", "classification_collision", "classification_crewincapacitation", "classification_debrisonrunway", "classification_deviationofatcinstructions", "classification_disruptiveorsickpassenger", "classification_doorwarning", "classification_doorwarningwhichone", "classification_dooropening", "classification_dooropeningwhichone", "classification_electricalfailure", "classification_emergencyevacuation", "classification_enginefailure", "classification_enginefire", "classification_fireorsmokeincabin", "classification_flapfailure", "classification_flattire", "classification_flightcontrolfailure", "classification_fuelleak", "classification_fuelquantity", "classification_hardlanding", "classification_icing", "classification_flightinstrument", "classification_flightinstrumentwhich", "classification_engineinstrument", "classification_engineinstrumentwhich", "classification_landinggear_blowdown", "classification_landinggear_failtoextend", "classification_landinggear_failtoretract", "classification_landinggear_hydraulicleak", "classification_landinggear_hydraulicsystemfailure", "classification_landinggear_falseindication", "classification_lighteningstrike", "classification_magnetofailedorrough", "classification_nearmidaircollision", "classification_paxinjury", "classification_propstrike", "classification_roughengine", "classification_runwayincursion", "classification_starterfailureorwarning", "classification_tailstrike", "classification_turbulence", "classification_vacuumfailure", "classification_waketurbulence", "classification_weatherbelowminimums", "classification_weatherbelowhighminimums", "classification_weightandbalance", "classification_windshear", "classification_other", "classification_othertext", "description");

$value = mysql_real_escape_string ( $_POST['search1field'] );

$select = "SELECT * FROM eventreport WHERE " . implode ( ' OR ', array_map ( create_function ( '$var', 'global $value;return $var . " LIKE %" . $value . "%";' ), $names ) ) . " LIMIT " . $rownumber . ", " . $limit;

$result = mysql_fetch_assoc ( $select );

?>[/code]

printf
Link to comment
Share on other sites

[quote]Then you produce a code abomination like this[/quote]

I would have to agree, some of the worst SQL Ive seen. You really need to learn some database design skills. This application is never going to stand up for any length of time and will be an absolute nightmare to try and maintain.
Link to comment
Share on other sites

I don't know what you guys are complaining about, I always look forward to his posts.

Array indexes start at [b]zero[/b].  This means they end at [b]count($array) - 1[/b].
[code]
<?php
//  build query
$names = array("name", "t_number", "flighttype", "aircrafttype", "aircraftnumber", "eventdate", "eventtime", "flightnumber", "flightnumberselect", "scheduleddepartureairport", "scheduledarrivalairport", "captain", "firstofficer", "flightattendant", "additionalcrewmembers", "weather", "flightplan", "pax", "lapchildren", "actiontaken_abortedtakeoff", "actiontaken_canceledflight", "actiontaken_declaredemergency", "actiontaken_delayedflight", "actiontaken_diversion", "actiontaken_goaround", "actiontaken_groundaircraftatoutstation", "actiontaken_inflightshutdown", "actiontaken_missedapproach", "actiontaken_returnaircrafttomaintenance", "actiontaken_returntogate", "actiontaken_turnback", "phaseofflight", "classification_aircraftdamage", "classification_aircraftonrunway", "classification_aircraftlogsmanualsorphase", "classification_airportclosure", "classification_alternatorfailure", "classification_atcdelay", "classification_avionicsfailure_communication", "classification_avionicsfailure_navigation", "classification_battery", "classification_birdstrike", "classification_brakefailure", "classification_collision", "classification_crewincapacitation", "classification_debrisonrunway", "classification_deviationofatcinstructions", "classification_disruptiveorsickpassenger", "classification_doorwarning", "classification_doorwarningwhichone", "classification_dooropening", "classification_dooropeningwhichone", "classification_electricalfailure", "classification_emergencyevacuation", "classification_enginefailure", "classification_enginefire", "classification_fireorsmokeincabin", "classification_flapfailure", "classification_flattire", "classification_flightcontrolfailure", "classification_fuelleak", "classification_fuelquantity", "classification_hardlanding", "classification_icing", "classification_flightinstrument", "classification_flightinstrumentwhich", "classification_engineinstrument", "classification_engineinstrumentwhich", "classification_landinggear_blowdown", "classification_landinggear_failtoextend", "classification_landinggear_failtoretract", "classification_landinggear_hydraulicleak", "classification_landinggear_hydraulicsystemfailure", "classification_landinggear_falseindication", "classification_lighteningstrike", "classification_magnetofailedorrough", "classification_nearmidaircollision", "classification_paxinjury", "classification_propstrike", "classification_roughengine", "classification_runwayincursion", "classification_starterfailureorwarning", "classification_tailstrike", "classification_turbulence", "classification_vacuumfailure", "classification_waketurbulence", "classification_weatherbelowminimums", "classification_weatherbelowhighminimums", "classification_weightandbalance", "classification_windshear", "classification_other", "classification_othertext", "description");
$values = mysql_real_escape_string($_POST['search1field']);
$values = "'%{$values}%'";
$select = "SELECT * FROM eventreport WHERE ";
for ($i=0;$i<=count($names) - 1;$i++) { // - 1
  // if ($i == 94) { // <-- WHY DO YOU INSERT RANDOM INTEGERS INTO YOUR CODE?
  if($i == count($names) - 1){
$select .= $names[$i] . " LIKE " . $values;
  } else {
    $select .= $names[$i] . " LIKE " . $values . " OR ";
  }
}
$select .= "LIMIT $rownumber, $limit;";
// end building query
?>[/code]

I already told you once about inserting random integers into your tests when you were doing your form validation, which I assume is still broken.

/popcorn
Link to comment
Share on other sites

[quote]roopurt18[/quote]
Thanks for the advice, and everyone else that helped.
I tried your idea, and it worked, I am getting more into "array's, building querys', and stuff lately, so that is why I am still new to this type.
I always did everything I did repetitively, but I got a lot of new functions for the framework.

Thanks again for the help.
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.