PHP - Creating Checkbox List And Populating From Multiple Mysql Tables
Ok, so I've spent quite a bit of time piecing together this solution from a variety of sources. As such, I may have something in my code below that doesn't make sense or isn't neccessary. Please let me know if that is the case.
I'm creating an administrative form that users will you to add/remove items from a MySQL table that lists open positions for a facility. The foreach loop generates all of the possible job specialties from a table called 'specialty_list'. This table is joined to a second table ('open_positions') that lists any positions that have been selected previously. Where I'm stuck is getting the checkbox to be checked if the facility_ID from the open_positions table matches the $id passed in the URL via ?facility_id=''. Here's where I am so far: $query = "SELECT specialty_list.specialty_displayname , specialty_shortname , open_positions.position , facility_ID FROM specialty_list LEFT OUTER JOIN open_positions ON open_positions.position = specialty_list.specialty_shortname ORDER BY specialty_list.specialty_shortname"; $results = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($results)) { $positions[$row['specialty_shortname']] = $row['specialty_displayname']; } echo "<form method='POST' action='checkbox.php'>"; foreach($positions as $specialty_shortname => $specialty_displayname) { $facility_ID = $row['facility_ID']; $checked = $facility_ID == $row['facility_ID'] ? ' checked' : ''; echo "<input type='checkbox' name='position[]' value=\"{$specialty_shortname}\"{$checked}> {$specialty_displayname}</input><br/>"; } echo "<input type='hidden' name='facility_ID' value='$id'>"; echo "<input type='submit' value='Submit Checkboxes!'>"; echo "</form>"; Any ideas how to get this working? I feel like I'm very close, but I just can't get it. I also tried starting from scratch with a WHILE statement instead of a FOREACH, but haven't tweaked it enough to prevent duplicate checkboxes. With that in mind, here it is, just in case that's a better direction: $query = "SELECT specialty_list.specialty_displayname , specialty_shortname , open_positions.position , facility_ID FROM specialty_list LEFT OUTER JOIN open_positions ON open_positions.position = specialty_list.specialty_shortname ORDER BY specialty_list.specialty_shortname"; $results = mysql_query($query) or die(mysql_error()); echo "<form method='POST' action='checkbox.php'>"; while($row=mysql_fetch_assoc($results)) { $facility_ID = $row['facility_ID']; $specialty_shortname = $row['specialty_shortname']; $specialty_displayname = $row['specialty_displayname']; if ($facililty_ID==$id) { $checked=' checked'; } echo "<input type='checkbox' name='position[]' value=\"$specialty_shortname\"$checked> $specialty_displayname</input><br/>"; } echo "<input type='hidden' name='facility_ID' value='$id'>"; echo "<input type='submit' value='Submit Checkboxes!'>"; echo "</form>"; Similar TutorialsHi, basically, here's the deal: I have a lit of checkboxes that are added by the admin (there's an unlimited amount, just depends on how many are added). Then, those are put in a form, in which the user picks whichever ones need to be chosen and those values get sent to a MySQL table. Here's the code that displays the checkboxes Code: [Select] <?php $sql="SELECT * FROM category ORDER BY categoryID ASC"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ echo "<input type='checkbox' id='". $row['categoryName'] ."' name='licensed[]' value='" . $row['categoryID'] ."' /><label for='". $row['categoryName'] ."'><br>" . $row['categoryName'] ."</label><br>"; } ?> What I'm making now, is an edit form where whichever checkboxes were checked, will show up checked in the edit form. But I'm not really sure how to go about this, since there is only one actual input tag in the code, I can't select the different ones. I also have this SQL query which selects whichever boxes were inputted into the DB Code: [Select] $sql2="SELECT * FROM category, categoryInfo WHERE category.categoryID = categoryInfo.categoryID AND categoryInfo.parentID = $parentID"; $result2=mysql_query($sql2); Where $parentID is the ID of whichever form you're editing. But yes, I'm basically not really sure how to go about this and would like some help figuring this out Thanks for your time yeah im back again with yet another thing i need some help lol. what im trying to do is set up a "Feature" box that will pull data from multiple tables by date. as of right now i would like to pull data from my "news" table and my "event" table. both need to be displayed differently. table contents: News ------- id date header news edate Event ------- id eventdate cdate header description image location so now I would like to make the mysql_query to get the info from both tables and list them by recent date. "date" and "cdate" are the dates i want the query to read from and of course display from most recent. I am trying to simplify my coding work for my website and wanting to make it operate more professionally (as part of my training to better my programming skills, which I know will take a lot of time to do). One of the things I`d like to improve on it is to create tables and fields in my mysql database, but not have to go into phpmyadmin to do it. I know open source programs like Drupal can do this easily so that when you add modules, the user does not have to access the database to set it up. But looking at the codes, I`m unable to figure out how it works. How will I be able to program my code to do something like, I`ll have a form where I enter in what I want the new table to be called, what fields to add in and their specifications, where I could do this by just going into my website as the admin? So first of all, I have a confession, I used Dreamweaver to take care of all my database work. Pheww. Now that I got that of my chest, I am having problems, not only with my lack of experience working with databases, but with my script also. I need to insert multiple checkbox values into my database into the same cell. So I have searched around and I thought I had found a fairly good approach, but with Dw's hodgepodge of overcomplicated mess, I am finding problems integrating it. The error I am getting post submission is "Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\gov\ballot.php on line 10 Column 'involvement' cannot be null" So if you would, could you debug my script and give me some instruction along to way so that I can learn a little something too? Here is my script: <?php require_once('Connections/ballot.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "Ballot")) { $insertSQL = sprintf("INSERT INTO votes (`first`, `last`, gender, grade, involvement, schedule, party, `time`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['first'], "text"), GetSQLValueString($_POST['last'], "text"), GetSQLValueString($_POST['gender'], "text"), GetSQLValueString($_POST['grade'], "text"), GetSQLValueString($_POST['involvement'], "text"), GetSQLValueString($_POST['schedule'], "text"), GetSQLValueString($_POST['party'], "text"), GetSQLValueString($_POST['time'], "text")); mysql_select_db($database_ballot, $ballot); $Result1 = mysql_query($insertSQL, $ballot) or die(mysql_error()); $insertGoTo = "thanks.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_ballot, $ballot); $query_Recordset1 = "SELECT * FROM votes"; $Recordset1 = mysql_query($query_Recordset1, $ballot) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Please Place your Vote Below</title> </head> <body style="background-image:url(images/bg.jpg); background-repeat:repeat-x; background-color:#000000;"> <table align="center" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="0"> <tr><td> <div style="border:thin; border-color:000000; border-style:groove; width:700px; background-color:ffffff;"> <div align="center"><a href="index.php"><img src="images/header.jpg" alt="Mock Elections 2010" /></a></div> <div style="margin:10px; margin-top:30px;"> Before continuing to vote, in order to count your vote, we ask that you please ensure you are adhereing to the following guidelines: </div> <div style="margin:30px"> <p>- When putting your name, remember to put your full legal name. NO nicknames.<br /> - Be sure that all your information is valid otherwise your vote will not be counted. <br /> </p> </div> <div style="margin-left:150px; margin-right:150px; margin-top:50px;"> <form action="<?php echo $editFormAction; ?>" method="POST" name="Ballot"> First Name: <input type="text" name="first" /><br /> Last Name: <input type="text" name="last" /><br /> <div>Gender: <label> Male <input type="radio" value="Male" name="gender" /></label> <label>Female <input type="radio" value="Female" name="gender" /></label> </div> Grade: <select name="grade"> <option selected="selected"> </option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="Teacher">Teacher</option> <option value="Staff">Staff</option> </select><br /> <div>Involvement: <label> <input type="checkbox" name="involvement[]" value="Athletics" id="involvement_0" /> Athletics</label> <label> <input type="checkbox" name="involvement[]" value="Co-Curricular" id="involvement_1" /> Co-Curricular</label> <label> <input type="checkbox" name="involvement[]" value="Clubs" id="involvement_2" /> Clubs</label> </div> <div>Schedule: <label><input type="radio" value="C4" name="schedule" />C4</label> <label><input type="radio" value="All Day" name="schedule" />All Day Hauser Student</label> </div> <div>Party: <label><input type="radio" value="PokePartay" name="party" />PokePartay</label> <label><input type="radio" value="Equilibrium" name="party" />Equilibrium Party</label> </div> <br /> <input type="Submit" value="Submit" /> <input type="hidden" value="<?php $tz = new DateTimeZone('America/Indianapolis'); $date = new DateTime('now', $tz); echo $date->format('m-d-Y h:i:s') . "\n"; ?>" name="time" /> <?php if (isset($_POST['submit'])) { $involvements = $_POST['involvement']; foreach($involvements as $involvement) { $query2 = "INSERT INTO votes (involvement) VALUES ('$involvement')"; $result2 = mysql_query($ballot, $query2) or die(mysql_error()); } } ?> <input type="hidden" name="MM_insert" value="Ballot" /> </form> </div> <br /> <br /> <br /> <br /> </div> </td> </tr> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> Thanks, Philip Ulrich Hey guys, I can't wrap my head around how to make this work right... I have three tables: Code: [Select] CREATE TABLE `games` ( `g_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(150) DEFAULT NULL, PRIMARY KEY (`g_id`)); CREATE TABLE IF NOT EXISTS `game_player` ( `r_id` int(11) NOT NULL AUTO_INCREMENT, `p_id` int(11) DEFAULT NULL, `g_id` int(11) DEFAULT NULL, `bool` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`r_id`)); CREATE TABLE IF NOT EXISTS `players` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `playerid` varchar(150) NOT NULL, PRIMARY KEY (`p_id`), UNIQUE KEY `playerid` (`playerid`)); The players table is my list of users, and they're tied to the list of games via the game_player table. So here's my issue... I'm trying to show the full list of games, and then check mark each record where the player does play it. This is what I have so far - it shows all the games, but it's not checking the boxes. Code: [Select] $result = mysql_query("SELECT * FROM games") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $newquery = "SELECT * FROM game_player, players WHERE game_player.p_id = players.p_id AND game_player.g_id = ".$row['g_id']. " AND players.playerid = {$userid}"; $query = mysql_query($newquery) or die(mysql_error()); if($query['bool'] == 1) { $set_checked = " CHECKED"; } else{ $set_checked = ""; } echo "<input type=\"checkbox\" name=\"box1\" value=\"".$query['g_id']."\"" . $set_checked . "/>".$row['name']."<br />\n"; } Hi, So I'm trying to make a car rental project, and I need to show cars of a specific type, available in a specific period. I'm currently using this query: SELECT * FROM car, reservations WHERE car.car_id = reservations.car AND car.type = 1 AND reservations.reserved_from >= "2011-12-22" AND reservations.reserved_to <= "2012-12-20"; So this returns all the cars of the type 1 reserved in 2011-12-22 - 2012-12-20 period. So know that I know which cars are unavailable, how would you go ahead and pick out what's left? Hi guys, I'm trying to query two tables for different data and echo the results that match both tables. Here are the tables I have and the query I'm trying to run. (Table) qc_reports (Fields) id report_date report_lot_number report_po report_supplier report_buyer report_inspectedby report_pulptemprange report_carrierconditions report_supplierclaim report_carrierclaim report_temprecorder report_temprange_N report_temprange_M report_temprange_B report_suppliercontact report_contactedby report_time report_comments (Table) qc_lots (Fields) id report_id lot_temprange lot_commodity lot_rpcs lot_brand lot_terms lot_cases lot_orgn lot_estnum lot_avgnum This is the query that I'm trying to do. Code: [Select] <?php $sql = "SELECT * FROM qc_reports, qc_lots WHERE "; if (!empty($start_date) and !empty($end_date)) $sql .= " qc_reports.report_date BETWEEN '$start_date' and '$end_date' AND "; if (!empty($search_fronteralot)) $sql .= " qc_reports.report_lot_number = '$search_fronteralot' AND "; if (!empty($search_buyer)) $sql .= " qc_reports.report_buyer = '$search_buyer' AND "; if (!empty($search_supplier)) $sql .= " qc_reports.report_supplier = '$search_supplier' AND "; if (!empty($search_po)) $sql .= " qc_reports.report_po = '$search_po' AND "; if (!empty($search_carrierconditions) and $search_carrierconditions != 'all') $sql .= " qc_reports.report_carrierconditions = '$search_carrierconditions' AND "; if (!empty($search_commodity) and $search_commodity != 'all') $sql .= " qc_lots.lot_commodity = '$search_commodity' AND "; if (!empty($search_inspectedby)) $sql .= " qc_reports.report_inspectedby = '$search_inspectedby' AND "; $sql = substr($sql, 0, -4); $query = mysql_query($sql); $numrows = mysql_num_rows($query); ?> RESULTS - <?php echo $numrows; ?> <hr> <table width='500'><tr><td><b>Date</b></td><td><b>Lot Number</b></td><td><b>PO</b></td><td> </td></tr> <tr> <td> </td> </tr> <?php while ($row = mysql_fetch_assoc($query)) { $id = stripslashes($row['id']); $report_lot_number = stripslashes($row['report_lot_number']); $report_po = stripslashes($row['report_po']); $report_date = stripslashes($row['report_date']); echo "<tr> <td>" . $report_date . "</td></td><td>" . $report_lot_number . "</td><td>" . $report_po . "</td><td><a href='view_report.php?id=" . $id . "'>View</a></td> </tr>"; } echo '</table><br><br><br><hr><br><br>'; } ?> All the variables are passed from a HTML form with $_POST. I need the search to work like this: If there is a value in a form field then the query gets appended with that value but when it gets to the $search_commodity it needs to search the second table (qc_lots) and check for the results. Any results that match have to be matched to the results from the first table (qc_reports) and display (echo) only qc_reports that match to both tables. The only common field is the report_id on the qc_lots table and the id on the qc_reports table. I'm stuck and need some guidance. Can someone help please? Not sure if this topic goes in here, it is related to PHP but also MySql, so if i'm on the wrong board sorry! What i'm trying to do is search for a keyword in 5 different tables and return the keyword ID from the table that its in The tables i'm trying to search are as follow location state county region continent The "location" table has all the locations i.e cities and each row has the following columns: id | continent_id | country_id | state_id | region_id | city_name The "state" table is set the the following: id | name "county" table : id | name "region" table: id | region and "continent" table id | name The way it works is the can search for any city or state or county or region or continent and ideally it should look into the five different tables and return the id of that table. So if the use searches for United States it will look for United States in all five tables, obviously it would find it in the "country" table so it should return that "id". The results are returned in "json format" Below is the code i have: Code: [Select] <? $input = $_GET['keyword']; $data = array(); /* In this query i'm attempting to search in all databases, but i'm not sure if i'm doing this right. I'm not getting any results so i know something is wrong just don't know how to write it. */ $query = mysql_query("SELECT * FROM locations JOIN states ON states.id = locations.state_id JOIN countries ON countries.id=locations.country_id JOIN regions ON regions.region_id = locations.region_id JOIN continents ON continents.id=locations.continent_id WHERE name LIKE '$input%' OR state LIKE '$input%' OR region LIKE '$input%' OR country LIKE '$input%' OR continent LIKE '$input%'") or die(mysql_error()); /* Here the values are added to to the $json array. The "value" should be the "id" from the table that the keyword matched. The 'name' Should be the name of the actual keyword. Again if they search for United States the "id" will come from the "countries" table and the "value" would come from the "countries" table as the name */ while ($row = mysql_fetch_assoc($query)) { $json = array(); $json['value'] = $row['id']; $json['name'] = $row['name']; $data[] = $json; } header("Content-type: application/json"); echo json_encode($data); ?> Any help would he be appreciated, i don't want people to do it for me, but rather just guide me a little bit.
Basically I want to add up multiple tables and display a grand total on my page when the radio button is pressed. The radio button has values that connect to my database and the values link to and ID with a price. How can I use this code in order to work out a grand total? Many thanks. I have searched everywhere but found nothing. I'm making a checklist. One table holds the list with IDs. There are about 224 rows, each with its own ideas. Now I have another table to hold user accounts. When you create an account, it shows you a fresh new checklist that you need to start checking off. Could anyone please share techniques so I can have multiple accounts have their own list they need to check off? (ie, when a new person creatures a new account they should have their own list with NOTHING checked) The only way I can think of doing this is making 224 fields for the user account with the IDs of the checklist table to check if I checked it or not. Surely there's an easier way? Thanks hi, I have a form that has 2 lists, first one has the months from Jan to Dec which i am done with, for the second list i want to have years from current year for other say 5 years. Example, we are in 2020 so i should have the list populate 2020,2021,2022,2023,2024 and next year it should show 2021-2025, how to do that. Here is what i have as HTML: <html> <head> <link rel="stylesheet" type="text/css" href="reportstyle.css"> </head> <body> <div class="form-wrapper"> <form action="reportanalysis.php" method="post"> <div class="form-item"> <h4>Select a month:</h4> <select id="months" name="months" required="required"> <option selected="selected" value="chose">Choose one option...</option> <option value="jan">Jan - 01</option> <option value="feb">Feb - 02</option> <option value="mar">Mar - 03</option> <option value="apr">Apr - 04</option> <option value="may">May - 05</option> <option value="jun">Jun - 06</option> <option value="jul">Jul - 07</option> <option value="aug">Aug - 08</option> <option value="sep">Sep - 09</option> <option value="oct">Oct - 10</option> <option value="nov">Nov - 11</option> <option value="dec">Dec - 12</option> </select> </div> <div class="form-item"> <h4>Select a year:</h4> <select id="years" name="years" required="required"> <option selected="selected" value="chose">Choose one option...</option> <option value="2020">2020</option> <option value="2021">2021</option> <option value="2022">2022</option> <option value="2023">2023</option> <option value="2024">2024</option> </select> </div> <div class="button-panel"> <center><button type="submit" name="reporting" class="buttonstyle">Generate Graph Report</button></center> </div> <div class="reminder"> <p><a href="home.php">Return to Main Menu</a> </div> </form> </div> </body> </html> Edited April 3, 2020 by ramiwahdan typo error Ok, so i got this website project dropped in my lap, and I'm stuck not really having done much php coding ever. I have a database which is linked already, and it was working when pulling data from a specific table. The problem arose when I was asked to make it work with other tables. I have a table with the table names in it, and the drop down field to select the table populates. The next field is a multiple select field that is supposed to populate report dates from the previously selected table, and then finally the last multiple select field is supposed to populate with names that match the dates selected from the previous field. The last one I can live without, as the existing code takes into account if the name selected doesn't exist in the table with the selected date, but at the moment the date field just comes up blank. Any help would be greatly appreciated. Hi, I use the following code to create a select menu from an array of options stored in LISTS.php: include 'LISTS.php'; print('<select id="from" name="from">'); foreach ($langList as $lang) {printf('<option %s>%s</option>', ($from1 == $lang ? 'selected="selected"' : ''), $lang); } echo '</select>'; where LISTS.php includes the following: $langList = array(' ','English', 'French', 'German', 'Dutch', 'Spanish'); This works great, but now I want to do something similar with a checkbox list, where each checkbox has an associated 'onchange' javascript function and I'm getting pretty stuck. My checkbox list is of the following form: Code: [Select] <html> <ul style="height: 95px; overflow: auto; width: 200px; border: 1px solid #480091; list-style-type: none; margin: 0; padding: 0;"> <li id="li1b"><label for="chk1b"><input name="chk1b" id="chk1b" type="checkbox" onchange="function1('chk1b','li1b')">Option1</label></li> <li id="li2b"><label for="chk2b"><input name="chk2b" id="chk2b" type="checkbox" onchange="function1('chk2b','li2b')">Option2</label></li> //etc. </ul> </html> What I want to do is have 'Option1', 'Option2', etc. stored in an array in LISTS.php and have a PHP script that populates the checkbox list accordingly, in a similar manner to my select menu above. I can't work out how to get the ID of the next <li> and the next <input> in the list to go up by one each time, e.g. 'li1b' then 'li2b', 'li3b', etc. Could someone pls help me out? Thanks! Hi all How do I modify the below code to search multiple tables in mySQL database? $query = "select * from store_items where description like \"%$trimmed%\" or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); It is for a search function and I need it to search another table called 'about_text' and 'faq_text' Thanks Pete Hello all, I am trying to learn OOP in PHP so please forgive my ignorance. I seem to be having difficulty inserting data into my database from checkbox items. My database has a column for each each fruit. I would like for each column to be populated with either a one(1) for checked or a zero(0) for not checked. Currently, my attempts have failed. I can either get all checkboxes to insert all zeros or I can get the first column to insert a one(1) while the others as zeros. Is there anybody here that can help me figure out what I am doing wrong and help me to re-work my code so I can get this to work? If anybody can help me using OOP methods that would be fantastic. Thank you all in advance.
$preffruit->create_preffruit(array( 'fruit_apple' => escape(Input::get(['fruit_selection'][0]) ? 1 : 0), 'fruit_orange' => escape(Input::get(['fruit_selection'][1]) ? 1 : 0), 'fruit_banana' => escape(Input::get(['fruit_selection'][2]) ? 1 : 0), 'fruit_pear' => escape(Input::get(['fruit_selection'][3]) ? 1 : 0), 'fruit_kiwi' => escape(Input::get(['fruit_selection'][4]) ? 1 : 0) )); <input type="checkbox" name="fruit_selection[]" value="fruit_apple"> <input type="checkbox" name="fruit_selection[]" value="fruit_orange"> <input type="checkbox" name="fruit_selection[]" value="fruit_banana"> <input type="checkbox" name="fruit_selection[]" value="fruit_pear"> <input type="checkbox" name="fruit_selection[]" value="fruit_kiwi"> public function insert_preffruit($table, $fields = array()) { $keys = array_keys($fields); $values = ''; $x = 1; foreach($fields as $field) { $values .= '?'; if($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO preffruit (`user_id`, `" . implode('`, `', $keys) . "`) VALUES (LAST_INSERT_ID(), {$values})"; if(!$this->query($sql, $fields)->error()) { return true; } return false; } Edited September 23, 2020 by ke-jo Dear All, I have attached here with a schema, of MySql DB format i am refering to for the topic i need help on. I want to know what is the best way to achieve this problem / task. I have a profile table, and a category table, and a table to map profiles to category. Which allows me to define/add into the category_profile_mapping table, profile ids against a category id. Each category can have anywhere between 2 to 1,00,000 profiles mapped to it. I have another table called sms_out. hence on the site, when i select a category and submit the form value with message, i want to know what is the best way to populate sms_out with MSISDN from the table "Profile" and the message from the form. The list of MSISDN will be based on the category id selected, hence the profile id's will be available in the category_profile_mapping table. I am bad at explaining the problem, however incase you folks need more info do let me know. i shall be glad to provide the same to .. all of you guys who are willing to help me PS: I am asking this question, cuz i want to knw the best solution to achieve this, when there is entries in millions to be done at one form submit. [attachment deleted by admin] Alright so I created a MySQL database that has 5 tables each named a brand of a dirt bike. In each table their are 2 fields, one INDEX_ID and MODELS. Under that for rows I have every model bike named. A quick question before I get onto what I want to do: Can data be added underneath the rows? For example, users will be able to submit information about each bike model. If each bike model is a row, can there be a category past that row or do I need to make each field a model name and just have a ton of fields and have the rows be the information users submit. To make it easier to understand I'll post the SQL code for the brand Honda: CREATE TABLE `Honda` ( `INDEX_ID` int(3) NOT NULL auto_increment, `MODELS` varchar(20) collate latin1_general_ci NOT NULL, PRIMARY KEY (`INDEX_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=23 ; -- -- Dumping data for table `Honda` -- INSERT INTO `Honda` VALUES(1, 'CR85'); INSERT INTO `Honda` VALUES(2, 'CR125'); INSERT INTO `Honda` VALUES(3, 'CR250'); INSERT INTO `Honda` VALUES(4, 'CRF100'); INSERT INTO `Honda` VALUES(5, 'CRF150'); INSERT INTO `Honda` VALUES(6, 'CRF230'); INSERT INTO `Honda` VALUES(7, 'CRF250X'); INSERT INTO `Honda` VALUES(8, 'CRF250R'); INSERT INTO `Honda` VALUES(9, 'CRF450X'); INSERT INTO `Honda` VALUES(10, 'CRF450R'); INSERT INTO `Honda` VALUES(11, 'CRF50'); INSERT INTO `Honda` VALUES(12, 'CRF70'); INSERT INTO `Honda` VALUES(13, 'CRF80'); INSERT INTO `Honda` VALUES(14, 'XR650'); INSERT INTO `Honda` VALUES(15, 'CR500'); INSERT INTO `Honda` VALUES(16, 'XR100'); INSERT INTO `Honda` VALUES(17, 'XR200'); INSERT INTO `Honda` VALUES(18, 'XR250'); INSERT INTO `Honda` VALUES(19, 'XR400'); INSERT INTO `Honda` VALUES(20, 'XR50'); INSERT INTO `Honda` VALUES(21, 'XR70'); INSERT INTO `Honda` VALUES(22, 'XR80'); Anyway I still need to figure out how to have this under a form that a user can use to select the bike they want to submit information about. A code like this perhaps?: <? $connection = mysql_connect("localhost","user","pass"); $fields = mysql_list_fields("dbname", "table", $connection); $columns = mysql_num_fields($fields); echo "<form action=page_to_post_to.php method=POST><select name=Field>"; for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } echo "</select></form>"; ?> Thanks. |