logo
down
shadow

Adding multiple checkbox values to multiple columns in a single row


Adding multiple checkbox values to multiple columns in a single row

By : user2950208
Date : November 17 2020, 11:52 AM
Does that help Since your values are 1-4, you could use a for loop to check if each value is in the POST array and then create your $itemSizing string -
code :
//a size array
$itemSizingArray = array();

//for loop for each size value
for($i=1;$i<=4;$i++){
    //add either a '1' or 'NULL' to the array, based on if the checkbox value is in the array
    $itemSizingArray[] = (in_array($i,$_POST["itemSize"]) ? 1: 'NULL');
}
//implode the array
$itemSizing = implode(', ',$itemSizingArray);
NULL, 1, NULL, 1


Share : facebook icon twitter icon
To retrieve values from multiple rows into a single row from a single table under multiple columns

To retrieve values from multiple rows into a single row from a single table under multiple columns


By : kidinthehall
Date : March 29 2020, 07:55 AM
I hope this helps . Here is an example table for my problem: , You can try this:
code :
SELECT 
    e1.id,
    e1.university as uvr1,
    e1.subjects as sub1,
    e1.yearofpass as yop1,
    e1.percentmarks as pcm1,
    e2.university as uvr2,
    e2.subjects as sub2,
    e2.yearofpass as yop2,
    e2.percentmarks as pcm2,
    e3.university as uvr3,
    e3.subjects as sub3,
    e3.yearofpass as yop3,
    e3.percentmarks as pcm3
FROM 
    Education as e1
LEFT JOIN Education as e2
    ON e1.id = e2.id
    AND e2.edutype = e1.edutype+1
LEFT JOIN Education as e3
    ON e1.id = e3.id
    AND e3.edutype = e1.edutype+2
WHERE
    e1.edutype = 1
Adding multiple columns values from sql database in a php variable (without using an array name inhtml checkbox tag)

Adding multiple columns values from sql database in a php variable (without using an array name inhtml checkbox tag)


By : Dhruv Singhal
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Don't make $postSkills an array, let it be string. Store the skills in this by seperating them with '|' .
code :
               $queryStoreSecondaryInfo = $connection->query($sqlStoreSecondaryInfo);

               if( $queryStoreSecondaryInfo ){
                   echo "<br />Updated Secondary! <br />";
                   $sqlUpdatedSecondaryInfo = " SELECT * FROM students_skills 
                                                WHERE ID='$_SESSION[ID]'  
                                                AND Email='$Email' ";
                   $queryUpdatedSecondaryInfo = $connection->query($sqlUpdatedSecondaryInfo);
                   while( $row = $queryUpdatedSecondaryInfo->fetch_assoc() ){
                       $_SESSION["Landscaping"] = $row["Landscaping"];
                       $_SESSION["Cleaning"] = $row["Cleaning"];
                       $_SESSION["Delivery"] = $row["Delivery"];
                       $_SESSION["Music"] = $row["Music"];
                       $_SESSION["Maintenance"] = $row["Maintenance"];
                       $_SESSION["Decoration"] = $row["Decoration"];
                       $_SESSION["Painting"] = $row["Painting"];
                       $_SESSION["PetCare"] = $row["PetCare"];
                       $_SESSION["Tutoring"] = $row["Tutoring"];
                       $_SESSION["Vehicles"] = $row["Vehicles"];
                       $_SESSION["SnowRemoval"] = $row["SnowRemoval"];
                       $_SESSION["Other"] = $row["Other"];

                       foreach( $row as $skill => $value ){
                           $postSkills="";
                           if( $value == "1" ){

                               //if statement is true, add all column header names, 
                               //ie. $skill values, together, and store in a variable, eg. $postSkills

                               $postSkills .= "$skill|";

                           }
                           if($postSkills!="") {
                               $postSkills = substr($postSkills,0,-1);
                           }
                           echo $postSkills;
                       }
                   }
               } 
$postSkills = "Landscaping|Cleaning|Decoration|Vehicles";
    $skillsArr = explode("|", $postSkills);

    foreach($skillsArr as $skill) {
        $_SESSION["$skill"] = 1;
    }
how to fetch multiple columns containing multiple values using a specific value from single table in PHP/MYSQL

how to fetch multiple columns containing multiple values using a specific value from single table in PHP/MYSQL


By : BANQATAH
Date : March 29 2020, 07:55 AM
I hope this helps you . I want to fetch multiple columns containing multiple values using a specific value from single table in PHP/MYSQL. , Try this REGEXP '[[:<:]]1[[:>:]]'
code :
"SELECT Name FROM table where s_id REGEXP '[[:<:]]1[[:>:]]'"
How to store multiple checkbox values in multiple columns of same table in database using PHP?

How to store multiple checkbox values in multiple columns of same table in database using PHP?


By : Q_Clay
Date : March 29 2020, 07:55 AM
will help you You have not posted the table structure but anyways I will try to give my best suggestions here.
Existing System:
code :
id,(other columns),choice1, choice2, choice3, choice4
checkbox table
--------------

id, checkbox_name, checkbox_value(if any)

teachers table
--------------

id, cols (other columns which I dont know whether its there or not)

teachers_choices //This is the checkbox selected table
----------------

id, teacher_id(this references to teacher table), checkbox_id (this references to checkbox table)
I want to insert multiple checkbox values in multiple columns but same table

I want to insert multiple checkbox values in multiple columns but same table


By : abhishek saha
Date : March 29 2020, 07:55 AM
it should still fix some issue You shouldn't be concatenating all the checkbox values. Each INSERT query needs to insert just the current element of $checkbox. You should also use a prepared statement to protect against SQL injection.
You also don't need two loops, just one.
code :
$N = count($checkbox1);
echo("<p>You selected $N techno(s): ");
$stmt = mysqli_prepare($connection, "INSERT INTO order_table (item_ID) values (?)");
mysqli_stmt_bind_param($stmt, "i", $chk1);
$success = true;
foreach($checkbox1 as $chk1) {
    if (!mysqli_stmt_execute($stmt)) {
        $success = false;
        break;
    }
}
if($success)  
{  
    echo'<script>alert("Inserted Successfully")</script>';  
}  
else  
{  
    echo'<script>alert("Failed To Insert")</script>';  
}  
Related Posts Related Posts :
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • What's wrong with my PHP Script? T_String issue
  • how to call a function of another file without including that file
  • is_rgb function in php
  • transform the numbers to letters using php
  • How to catch an exception from another class method PHP
  • PHP exec is blocked by ISP
  • PHP4 to PHP5 migration character encoding. latin1 vs utf8
  • Begin Transaction not defined
  • How much harm can a user do with xss on a page unique to them?
  • How to import data from a php file to javascript variable
  • PHP and Javascript - log complete workflow
  • When I echo !!! 0 it gives me a strange result
  • jquery ajax post dies after submit
  • How to upload file with curl on sftp server
  • Advanced search using a text input to search through only one category
  • Why do I get "Non-static method App\Models\Category::products() should not be called statically" in laravel
  • Stop notices from undefined indexes in arrays
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org