How to build mysql query with php on the fly












0















My head is smoking ;-) and with all the info i read here, i did not get the resolution.



I have a form like this:
the form



i need to build a Mysql Query select on the fly. The checkboxes can be different selected. Only one or two or three or four or..., its up to the User. From the selected checkboxes i need to build the Mysql query.
i really will appreciate it, some one can help me.



This is my function. so far... i need to add the AND for the sql query.
i did try a lot but nothing works.



    function wdw_get_data_answer_select($mysqli, $array_selected) {
$sql_1 = '';
foreach ($array_selected as $key => $value) {
if ($key == 'gender' && !empty($value)) { $sql_1 .= "gender = '".$value."'"; }
if ($key == 'age' && !empty($value)) { $sql_1 .= "age = '".$value."'"; }
if ($key == 'education' && !empty($value)) { $sql_1 .= "education = '".$value."'"; }
if ($key == 'department' && !empty($value)) { $sql_1 .= "department = '".$value."'"; }
}
$sql = "SELECT `gender`,`age`,`education`,`department`,`code_numbers` FROM ".TABLE_ANSWERS_BASIC_SELECT." WHERE ".$sql_1;
if ($stmt = $mysqli->prepare($sql)) {
$stmt->execute();
$stmt->store_result();
//printf("Errormessage: %sn", $mysqli->error);
if ($stmt->num_rows > 0 ) {
$stmt->bind_result($gender, $age, $education, $department, $code_numbers);
while ($stmt->fetch()) {
$select_content .= $code_numbers.',';
}
}
}
$stmt->close();
$select_content = substr($select_content, 0, -1);
return $select_content; }


thats the sql table



Example:
if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2



SELECT * FROM `TABLE` WHERE `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


and let say TEXT_AGE_3 don't have a TEXT_FEMALE how i can filter out the TEXT_MALE?
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


works but
but if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2 AND TEXT_DEPARTMENT_1 AND TEXT_DEPARTMENT_2
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2 and `department` = TEXT_DEPARTMENT_1 or `department` = TEXT_DEPARTMENT_2


the selected answer is not corect.




  • TEXT_FEMALE Ženska

  • TEXT_MALE Moški

  • TEXT_AGE_1 Pod 30 let

  • TEXT_AGE_2 Nad 30 do 50 let

  • TEXT_AGE_3 Nad 50 let

  • TEXT_EDUCATION_1 Poklicno usposabljanje

  • TEXT_EDUCATION_2 Študija

  • TEXT_EDUCATION_3 Niti

  • TEXT_DEPARTMENT_1 Proizvodnja

  • TEXT_DEPARTMENT_2 Uprava

  • TEXT_DEPARTMENT_3 Drugo (Vzdrževanje, Logistika, Kakovost)


I hope I have explained it understandably.
I am a german guy. I hope my english is okay ;-)










share|improve this question

























  • it would be easiest to use an sql builder something like github.com/nilportugues/php-sql-query-builder this way you can loop through and add selects without having to worry about spaces and other things

    – Brice
    Nov 19 '18 at 20:30













  • I think you may also have an issue with your encoding on that table

    – Brice
    Nov 19 '18 at 20:44











  • the issue with my encoding i don't understand too. the datebase is Utf8 the meta tag on the website is utf8. the languages file is utf8 without BOM. i did read a lot about this issue her in stackoverflow too and i try a lot, but nothing works. I am quite familar with PHP and mysql more than 25 years and the encoding issue is only at this database. I dont't know why, its a server in Slowenia. I hope i will find a resolution for that sonn.

    – McMannehan
    Nov 20 '18 at 1:53













  • sorry, your answer have nothing do to with my problem. all the query builder follow the sql rules, have to of course. The problem is the creation on the fly and the correct select. if i use an sql query builder there not fix the problem. i will look further to find a resolution. Devlopment is time intensiv!!! :-)

    – McMannehan
    Nov 20 '18 at 2:59


















0















My head is smoking ;-) and with all the info i read here, i did not get the resolution.



I have a form like this:
the form



i need to build a Mysql Query select on the fly. The checkboxes can be different selected. Only one or two or three or four or..., its up to the User. From the selected checkboxes i need to build the Mysql query.
i really will appreciate it, some one can help me.



This is my function. so far... i need to add the AND for the sql query.
i did try a lot but nothing works.



    function wdw_get_data_answer_select($mysqli, $array_selected) {
$sql_1 = '';
foreach ($array_selected as $key => $value) {
if ($key == 'gender' && !empty($value)) { $sql_1 .= "gender = '".$value."'"; }
if ($key == 'age' && !empty($value)) { $sql_1 .= "age = '".$value."'"; }
if ($key == 'education' && !empty($value)) { $sql_1 .= "education = '".$value."'"; }
if ($key == 'department' && !empty($value)) { $sql_1 .= "department = '".$value."'"; }
}
$sql = "SELECT `gender`,`age`,`education`,`department`,`code_numbers` FROM ".TABLE_ANSWERS_BASIC_SELECT." WHERE ".$sql_1;
if ($stmt = $mysqli->prepare($sql)) {
$stmt->execute();
$stmt->store_result();
//printf("Errormessage: %sn", $mysqli->error);
if ($stmt->num_rows > 0 ) {
$stmt->bind_result($gender, $age, $education, $department, $code_numbers);
while ($stmt->fetch()) {
$select_content .= $code_numbers.',';
}
}
}
$stmt->close();
$select_content = substr($select_content, 0, -1);
return $select_content; }


thats the sql table



Example:
if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2



SELECT * FROM `TABLE` WHERE `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


and let say TEXT_AGE_3 don't have a TEXT_FEMALE how i can filter out the TEXT_MALE?
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


works but
but if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2 AND TEXT_DEPARTMENT_1 AND TEXT_DEPARTMENT_2
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2 and `department` = TEXT_DEPARTMENT_1 or `department` = TEXT_DEPARTMENT_2


the selected answer is not corect.




  • TEXT_FEMALE Ženska

  • TEXT_MALE Moški

  • TEXT_AGE_1 Pod 30 let

  • TEXT_AGE_2 Nad 30 do 50 let

  • TEXT_AGE_3 Nad 50 let

  • TEXT_EDUCATION_1 Poklicno usposabljanje

  • TEXT_EDUCATION_2 Študija

  • TEXT_EDUCATION_3 Niti

  • TEXT_DEPARTMENT_1 Proizvodnja

  • TEXT_DEPARTMENT_2 Uprava

  • TEXT_DEPARTMENT_3 Drugo (Vzdrževanje, Logistika, Kakovost)


I hope I have explained it understandably.
I am a german guy. I hope my english is okay ;-)










share|improve this question

























  • it would be easiest to use an sql builder something like github.com/nilportugues/php-sql-query-builder this way you can loop through and add selects without having to worry about spaces and other things

    – Brice
    Nov 19 '18 at 20:30













  • I think you may also have an issue with your encoding on that table

    – Brice
    Nov 19 '18 at 20:44











  • the issue with my encoding i don't understand too. the datebase is Utf8 the meta tag on the website is utf8. the languages file is utf8 without BOM. i did read a lot about this issue her in stackoverflow too and i try a lot, but nothing works. I am quite familar with PHP and mysql more than 25 years and the encoding issue is only at this database. I dont't know why, its a server in Slowenia. I hope i will find a resolution for that sonn.

    – McMannehan
    Nov 20 '18 at 1:53













  • sorry, your answer have nothing do to with my problem. all the query builder follow the sql rules, have to of course. The problem is the creation on the fly and the correct select. if i use an sql query builder there not fix the problem. i will look further to find a resolution. Devlopment is time intensiv!!! :-)

    – McMannehan
    Nov 20 '18 at 2:59
















0












0








0








My head is smoking ;-) and with all the info i read here, i did not get the resolution.



I have a form like this:
the form



i need to build a Mysql Query select on the fly. The checkboxes can be different selected. Only one or two or three or four or..., its up to the User. From the selected checkboxes i need to build the Mysql query.
i really will appreciate it, some one can help me.



This is my function. so far... i need to add the AND for the sql query.
i did try a lot but nothing works.



    function wdw_get_data_answer_select($mysqli, $array_selected) {
$sql_1 = '';
foreach ($array_selected as $key => $value) {
if ($key == 'gender' && !empty($value)) { $sql_1 .= "gender = '".$value."'"; }
if ($key == 'age' && !empty($value)) { $sql_1 .= "age = '".$value."'"; }
if ($key == 'education' && !empty($value)) { $sql_1 .= "education = '".$value."'"; }
if ($key == 'department' && !empty($value)) { $sql_1 .= "department = '".$value."'"; }
}
$sql = "SELECT `gender`,`age`,`education`,`department`,`code_numbers` FROM ".TABLE_ANSWERS_BASIC_SELECT." WHERE ".$sql_1;
if ($stmt = $mysqli->prepare($sql)) {
$stmt->execute();
$stmt->store_result();
//printf("Errormessage: %sn", $mysqli->error);
if ($stmt->num_rows > 0 ) {
$stmt->bind_result($gender, $age, $education, $department, $code_numbers);
while ($stmt->fetch()) {
$select_content .= $code_numbers.',';
}
}
}
$stmt->close();
$select_content = substr($select_content, 0, -1);
return $select_content; }


thats the sql table



Example:
if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2



SELECT * FROM `TABLE` WHERE `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


and let say TEXT_AGE_3 don't have a TEXT_FEMALE how i can filter out the TEXT_MALE?
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


works but
but if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2 AND TEXT_DEPARTMENT_1 AND TEXT_DEPARTMENT_2
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2 and `department` = TEXT_DEPARTMENT_1 or `department` = TEXT_DEPARTMENT_2


the selected answer is not corect.




  • TEXT_FEMALE Ženska

  • TEXT_MALE Moški

  • TEXT_AGE_1 Pod 30 let

  • TEXT_AGE_2 Nad 30 do 50 let

  • TEXT_AGE_3 Nad 50 let

  • TEXT_EDUCATION_1 Poklicno usposabljanje

  • TEXT_EDUCATION_2 Študija

  • TEXT_EDUCATION_3 Niti

  • TEXT_DEPARTMENT_1 Proizvodnja

  • TEXT_DEPARTMENT_2 Uprava

  • TEXT_DEPARTMENT_3 Drugo (Vzdrževanje, Logistika, Kakovost)


I hope I have explained it understandably.
I am a german guy. I hope my english is okay ;-)










share|improve this question
















My head is smoking ;-) and with all the info i read here, i did not get the resolution.



I have a form like this:
the form



i need to build a Mysql Query select on the fly. The checkboxes can be different selected. Only one or two or three or four or..., its up to the User. From the selected checkboxes i need to build the Mysql query.
i really will appreciate it, some one can help me.



This is my function. so far... i need to add the AND for the sql query.
i did try a lot but nothing works.



    function wdw_get_data_answer_select($mysqli, $array_selected) {
$sql_1 = '';
foreach ($array_selected as $key => $value) {
if ($key == 'gender' && !empty($value)) { $sql_1 .= "gender = '".$value."'"; }
if ($key == 'age' && !empty($value)) { $sql_1 .= "age = '".$value."'"; }
if ($key == 'education' && !empty($value)) { $sql_1 .= "education = '".$value."'"; }
if ($key == 'department' && !empty($value)) { $sql_1 .= "department = '".$value."'"; }
}
$sql = "SELECT `gender`,`age`,`education`,`department`,`code_numbers` FROM ".TABLE_ANSWERS_BASIC_SELECT." WHERE ".$sql_1;
if ($stmt = $mysqli->prepare($sql)) {
$stmt->execute();
$stmt->store_result();
//printf("Errormessage: %sn", $mysqli->error);
if ($stmt->num_rows > 0 ) {
$stmt->bind_result($gender, $age, $education, $department, $code_numbers);
while ($stmt->fetch()) {
$select_content .= $code_numbers.',';
}
}
}
$stmt->close();
$select_content = substr($select_content, 0, -1);
return $select_content; }


thats the sql table



Example:
if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2



SELECT * FROM `TABLE` WHERE `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


and let say TEXT_AGE_3 don't have a TEXT_FEMALE how i can filter out the TEXT_MALE?
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2;


works but
but if checkbox selected like
TEXT_FEMALE and TEXT_AGE_2 and TEXT_AGE_3 TEXT_EDUCATION_2 AND TEXT_DEPARTMENT_1 AND TEXT_DEPARTMENT_2
i did try



SELECT * FROM `TABLE` WHERE `gender` IN('TEXT_FEMALE') and `gender` = TEXT_FEMALE and `age` = TEXT_AGE_2 or `age` = TEXT_AGE_3 and `education` = TEXT_EDUCATION_2 and `department` = TEXT_DEPARTMENT_1 or `department` = TEXT_DEPARTMENT_2


the selected answer is not corect.




  • TEXT_FEMALE Ženska

  • TEXT_MALE Moški

  • TEXT_AGE_1 Pod 30 let

  • TEXT_AGE_2 Nad 30 do 50 let

  • TEXT_AGE_3 Nad 50 let

  • TEXT_EDUCATION_1 Poklicno usposabljanje

  • TEXT_EDUCATION_2 Študija

  • TEXT_EDUCATION_3 Niti

  • TEXT_DEPARTMENT_1 Proizvodnja

  • TEXT_DEPARTMENT_2 Uprava

  • TEXT_DEPARTMENT_3 Drugo (Vzdrževanje, Logistika, Kakovost)


I hope I have explained it understandably.
I am a german guy. I hope my english is okay ;-)







php mysqli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 20:13







McMannehan

















asked Nov 19 '18 at 20:06









McMannehanMcMannehan

33




33













  • it would be easiest to use an sql builder something like github.com/nilportugues/php-sql-query-builder this way you can loop through and add selects without having to worry about spaces and other things

    – Brice
    Nov 19 '18 at 20:30













  • I think you may also have an issue with your encoding on that table

    – Brice
    Nov 19 '18 at 20:44











  • the issue with my encoding i don't understand too. the datebase is Utf8 the meta tag on the website is utf8. the languages file is utf8 without BOM. i did read a lot about this issue her in stackoverflow too and i try a lot, but nothing works. I am quite familar with PHP and mysql more than 25 years and the encoding issue is only at this database. I dont't know why, its a server in Slowenia. I hope i will find a resolution for that sonn.

    – McMannehan
    Nov 20 '18 at 1:53













  • sorry, your answer have nothing do to with my problem. all the query builder follow the sql rules, have to of course. The problem is the creation on the fly and the correct select. if i use an sql query builder there not fix the problem. i will look further to find a resolution. Devlopment is time intensiv!!! :-)

    – McMannehan
    Nov 20 '18 at 2:59





















  • it would be easiest to use an sql builder something like github.com/nilportugues/php-sql-query-builder this way you can loop through and add selects without having to worry about spaces and other things

    – Brice
    Nov 19 '18 at 20:30













  • I think you may also have an issue with your encoding on that table

    – Brice
    Nov 19 '18 at 20:44











  • the issue with my encoding i don't understand too. the datebase is Utf8 the meta tag on the website is utf8. the languages file is utf8 without BOM. i did read a lot about this issue her in stackoverflow too and i try a lot, but nothing works. I am quite familar with PHP and mysql more than 25 years and the encoding issue is only at this database. I dont't know why, its a server in Slowenia. I hope i will find a resolution for that sonn.

    – McMannehan
    Nov 20 '18 at 1:53













  • sorry, your answer have nothing do to with my problem. all the query builder follow the sql rules, have to of course. The problem is the creation on the fly and the correct select. if i use an sql query builder there not fix the problem. i will look further to find a resolution. Devlopment is time intensiv!!! :-)

    – McMannehan
    Nov 20 '18 at 2:59



















it would be easiest to use an sql builder something like github.com/nilportugues/php-sql-query-builder this way you can loop through and add selects without having to worry about spaces and other things

– Brice
Nov 19 '18 at 20:30







it would be easiest to use an sql builder something like github.com/nilportugues/php-sql-query-builder this way you can loop through and add selects without having to worry about spaces and other things

– Brice
Nov 19 '18 at 20:30















I think you may also have an issue with your encoding on that table

– Brice
Nov 19 '18 at 20:44





I think you may also have an issue with your encoding on that table

– Brice
Nov 19 '18 at 20:44













the issue with my encoding i don't understand too. the datebase is Utf8 the meta tag on the website is utf8. the languages file is utf8 without BOM. i did read a lot about this issue her in stackoverflow too and i try a lot, but nothing works. I am quite familar with PHP and mysql more than 25 years and the encoding issue is only at this database. I dont't know why, its a server in Slowenia. I hope i will find a resolution for that sonn.

– McMannehan
Nov 20 '18 at 1:53







the issue with my encoding i don't understand too. the datebase is Utf8 the meta tag on the website is utf8. the languages file is utf8 without BOM. i did read a lot about this issue her in stackoverflow too and i try a lot, but nothing works. I am quite familar with PHP and mysql more than 25 years and the encoding issue is only at this database. I dont't know why, its a server in Slowenia. I hope i will find a resolution for that sonn.

– McMannehan
Nov 20 '18 at 1:53















sorry, your answer have nothing do to with my problem. all the query builder follow the sql rules, have to of course. The problem is the creation on the fly and the correct select. if i use an sql query builder there not fix the problem. i will look further to find a resolution. Devlopment is time intensiv!!! :-)

– McMannehan
Nov 20 '18 at 2:59







sorry, your answer have nothing do to with my problem. all the query builder follow the sql rules, have to of course. The problem is the creation on the fly and the correct select. if i use an sql query builder there not fix the problem. i will look further to find a resolution. Devlopment is time intensiv!!! :-)

– McMannehan
Nov 20 '18 at 2:59














2 Answers
2






active

oldest

votes


















0














with this library github.com/nilportugues/php-sql-query-builder you would do something like this



$builder = new MySqlBuilder(); 
$query = $builder->select()
->setTable('user')
->where();

foreach ($array_selected as $key => $value) {
$query->in($key,array($value));
}

echo $builder->writeformatted($query); // this will output the sql you need to run





share|improve this answer
























  • thank you for the answer. i will check it out today and i will inform about.

    – McMannehan
    Nov 20 '18 at 1:56











  • Unfortunately I am not able to use Composer nor any autoload because of the hosting company's restrictions and i don't use any local VM ware or WAMP. the explaning how to install without composer is missing. No explaining what class have to include. So i will check out to find another one, but in my opinion a tool like that will not help so much, because i have to prepare the selected checkbox value for that too. anyway if i get a resolution for my "problem" i will post this here. if someone have another idea, i really will appreciate more info and help. thank you

    – McMannehan
    Nov 20 '18 at 2:13













  • github.com/nilportugues/php-sql-query-builder haveis no documention. I did find a lot answer about this class file. I will not use it. anyway, thank you for the answer

    – McMannehan
    Nov 20 '18 at 2:35





















0














Now it's working. I did change the form. Instead of Checkboxes i use Radio buttons.
I create my own Query on the fly. Thanks to all for help!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381876%2fhow-to-build-mysql-query-with-php-on-the-fly%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    with this library github.com/nilportugues/php-sql-query-builder you would do something like this



    $builder = new MySqlBuilder(); 
    $query = $builder->select()
    ->setTable('user')
    ->where();

    foreach ($array_selected as $key => $value) {
    $query->in($key,array($value));
    }

    echo $builder->writeformatted($query); // this will output the sql you need to run





    share|improve this answer
























    • thank you for the answer. i will check it out today and i will inform about.

      – McMannehan
      Nov 20 '18 at 1:56











    • Unfortunately I am not able to use Composer nor any autoload because of the hosting company's restrictions and i don't use any local VM ware or WAMP. the explaning how to install without composer is missing. No explaining what class have to include. So i will check out to find another one, but in my opinion a tool like that will not help so much, because i have to prepare the selected checkbox value for that too. anyway if i get a resolution for my "problem" i will post this here. if someone have another idea, i really will appreciate more info and help. thank you

      – McMannehan
      Nov 20 '18 at 2:13













    • github.com/nilportugues/php-sql-query-builder haveis no documention. I did find a lot answer about this class file. I will not use it. anyway, thank you for the answer

      – McMannehan
      Nov 20 '18 at 2:35


















    0














    with this library github.com/nilportugues/php-sql-query-builder you would do something like this



    $builder = new MySqlBuilder(); 
    $query = $builder->select()
    ->setTable('user')
    ->where();

    foreach ($array_selected as $key => $value) {
    $query->in($key,array($value));
    }

    echo $builder->writeformatted($query); // this will output the sql you need to run





    share|improve this answer
























    • thank you for the answer. i will check it out today and i will inform about.

      – McMannehan
      Nov 20 '18 at 1:56











    • Unfortunately I am not able to use Composer nor any autoload because of the hosting company's restrictions and i don't use any local VM ware or WAMP. the explaning how to install without composer is missing. No explaining what class have to include. So i will check out to find another one, but in my opinion a tool like that will not help so much, because i have to prepare the selected checkbox value for that too. anyway if i get a resolution for my "problem" i will post this here. if someone have another idea, i really will appreciate more info and help. thank you

      – McMannehan
      Nov 20 '18 at 2:13













    • github.com/nilportugues/php-sql-query-builder haveis no documention. I did find a lot answer about this class file. I will not use it. anyway, thank you for the answer

      – McMannehan
      Nov 20 '18 at 2:35
















    0












    0








    0







    with this library github.com/nilportugues/php-sql-query-builder you would do something like this



    $builder = new MySqlBuilder(); 
    $query = $builder->select()
    ->setTable('user')
    ->where();

    foreach ($array_selected as $key => $value) {
    $query->in($key,array($value));
    }

    echo $builder->writeformatted($query); // this will output the sql you need to run





    share|improve this answer













    with this library github.com/nilportugues/php-sql-query-builder you would do something like this



    $builder = new MySqlBuilder(); 
    $query = $builder->select()
    ->setTable('user')
    ->where();

    foreach ($array_selected as $key => $value) {
    $query->in($key,array($value));
    }

    echo $builder->writeformatted($query); // this will output the sql you need to run






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 19 '18 at 20:52









    BriceBrice

    396211




    396211













    • thank you for the answer. i will check it out today and i will inform about.

      – McMannehan
      Nov 20 '18 at 1:56











    • Unfortunately I am not able to use Composer nor any autoload because of the hosting company's restrictions and i don't use any local VM ware or WAMP. the explaning how to install without composer is missing. No explaining what class have to include. So i will check out to find another one, but in my opinion a tool like that will not help so much, because i have to prepare the selected checkbox value for that too. anyway if i get a resolution for my "problem" i will post this here. if someone have another idea, i really will appreciate more info and help. thank you

      – McMannehan
      Nov 20 '18 at 2:13













    • github.com/nilportugues/php-sql-query-builder haveis no documention. I did find a lot answer about this class file. I will not use it. anyway, thank you for the answer

      – McMannehan
      Nov 20 '18 at 2:35





















    • thank you for the answer. i will check it out today and i will inform about.

      – McMannehan
      Nov 20 '18 at 1:56











    • Unfortunately I am not able to use Composer nor any autoload because of the hosting company's restrictions and i don't use any local VM ware or WAMP. the explaning how to install without composer is missing. No explaining what class have to include. So i will check out to find another one, but in my opinion a tool like that will not help so much, because i have to prepare the selected checkbox value for that too. anyway if i get a resolution for my "problem" i will post this here. if someone have another idea, i really will appreciate more info and help. thank you

      – McMannehan
      Nov 20 '18 at 2:13













    • github.com/nilportugues/php-sql-query-builder haveis no documention. I did find a lot answer about this class file. I will not use it. anyway, thank you for the answer

      – McMannehan
      Nov 20 '18 at 2:35



















    thank you for the answer. i will check it out today and i will inform about.

    – McMannehan
    Nov 20 '18 at 1:56





    thank you for the answer. i will check it out today and i will inform about.

    – McMannehan
    Nov 20 '18 at 1:56













    Unfortunately I am not able to use Composer nor any autoload because of the hosting company's restrictions and i don't use any local VM ware or WAMP. the explaning how to install without composer is missing. No explaining what class have to include. So i will check out to find another one, but in my opinion a tool like that will not help so much, because i have to prepare the selected checkbox value for that too. anyway if i get a resolution for my "problem" i will post this here. if someone have another idea, i really will appreciate more info and help. thank you

    – McMannehan
    Nov 20 '18 at 2:13







    Unfortunately I am not able to use Composer nor any autoload because of the hosting company's restrictions and i don't use any local VM ware or WAMP. the explaning how to install without composer is missing. No explaining what class have to include. So i will check out to find another one, but in my opinion a tool like that will not help so much, because i have to prepare the selected checkbox value for that too. anyway if i get a resolution for my "problem" i will post this here. if someone have another idea, i really will appreciate more info and help. thank you

    – McMannehan
    Nov 20 '18 at 2:13















    github.com/nilportugues/php-sql-query-builder haveis no documention. I did find a lot answer about this class file. I will not use it. anyway, thank you for the answer

    – McMannehan
    Nov 20 '18 at 2:35







    github.com/nilportugues/php-sql-query-builder haveis no documention. I did find a lot answer about this class file. I will not use it. anyway, thank you for the answer

    – McMannehan
    Nov 20 '18 at 2:35















    0














    Now it's working. I did change the form. Instead of Checkboxes i use Radio buttons.
    I create my own Query on the fly. Thanks to all for help!






    share|improve this answer




























      0














      Now it's working. I did change the form. Instead of Checkboxes i use Radio buttons.
      I create my own Query on the fly. Thanks to all for help!






      share|improve this answer


























        0












        0








        0







        Now it's working. I did change the form. Instead of Checkboxes i use Radio buttons.
        I create my own Query on the fly. Thanks to all for help!






        share|improve this answer













        Now it's working. I did change the form. Instead of Checkboxes i use Radio buttons.
        I create my own Query on the fly. Thanks to all for help!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 7:17









        McMannehanMcMannehan

        33




        33






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381876%2fhow-to-build-mysql-query-with-php-on-the-fly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word