PHP - Query Table And Return Sub-arrays
Given the following query,
SELECT t1.a, t1.b, t2.c FROM t1 INNER JOIN t2 ON t2.id=t1.t2_id WHERE t1.pk=123;I get the following three records: array( array('a'=>1,'b'=>2,'c'=>4), array('a'=>1,'b'=>2,'c'=>5), array('a'=>1,'b'=>2,'c'=>8) )What would be the best way to get just one record such as the following? array('a'=>1,'b'=>2, 'c'=>array(4,5,8))My thoughts were to use MySQL's GROUP_CONCAT, and then use implode() to turn it into an array, but didn't know if there was a better way. Thanks Similar TutorialsI have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! Hi I have a query where it returns a few fields based on the location. I created a class for the function and an index page. It does not return any values. Can someone please advise/ THE CLASS Code: [Select] <?php /**************************************** * * WIP Progress Class * * ****************************************/ class CHWIPProgress { var $conn; // Constructor, connect to the database public function __construct() { require_once "/var/www/reporting/settings.php"; define("DAY", 86400); if(!$this->conn = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) die(mysql_error()); if(!mysql_select_db(DB_DATABASE_NAME, $this->conn)) die(mysql_error()); } public function ListWIPOnLocation($location) { $sql = "SELECT `ProgressPoint.PPDescription` AS Description ,`Bundle.WorksOrder` AS WorksOrder, `Bundle.BundleNumber` AS Number, `Bundle.BundleReference` AS Reference,`TWOrder.DueDate` AS Duedate FROM `TWOrder`,`Bundle`,`ProgressPoint` WHERE `Bundle.CurrentProgressPoint`=`ProgressPoint.PPNumber` AND `TWOrder.Colour=Bundle.Colour` AND `TWOrder.Size=Bundle.Size` AND `TWOrder.WorksOrderNumber`=`Bundle.WorksOrder` AND `ProgressPoint.PPDescription` LIKE '" . $location . "%' ORDER BY TWOrder.DueDate DESC"; mysql_select_db(DB_DATABASE_NAME, $this->conn); $result = mysql_query($sql, $this->conn); echo $sql; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $return[] = $row; } return $return; } } ?> The index page Code: [Select] <?php // First of all initialise the user and check for permissions require_once "/var/www/users/user.php"; $user = new CHUser(7); // Initialise the template require_once "/var/www/template/template.php"; $template = new CHTemplate(); // And create a cid object require_once "/var/www/WIPProgress/DisplayWIPOnLocation.php"; $WIPProgress= new CHWIPProgress(); $content = "Check WIP Status on Location <br>"; $content = "<form action='index.php' method='get' name ='location'> <select id='location' > <option>Skin Room</option> <option>Clicking</option> <option>Kettering</option> <option>Closing</option> <option>Rushden</option> <option>Assembly</option> <option>Lasting</option> <option>Making</option> <option>Finishing</option> <option>Shoe Room</option> </select> <input type='submit' /> </form>"; $wip = $WIPProgress->ListWIPOnLocation($_GET['location']); // Now show the details $content .= "<h2>Detail</h2> <table> <tr> <th>PPDescription</th> <th>Works Order</th> <th>Bundle Number</th> <th>Bundle Reference</th> <th>Due Date</th> </tr>"; foreach($wip as $x) { $content .= "<tr> <td>" . $x['Description'] . "</td> <td>" . $x['WorksOrder'] . "</td> <td>" . $x['Number'] . "</td> <td>" . $x['Reference'] . "</td> <td>" . $x['DueDate'] . "</td> </tr>"; } $template->SetTag("content", $content); echo $template->Display(); ?> thank you Hi guys, im trying to connect to a database and get the value for the user in the row called 'user_credit', if it equals 1 or more then i want to show the ''You have £ ....'' bit in the script. Problem is nothing shows at all, even without the if statement. I have changed the value for me in the database so in user_credit the value is 100, which is more than 1 so it should appear. I have probably done something wrong. Any ideas? Code: [Select] <? include '../admin/database/membership_dbc.php'; $r = mysql_query("SELECT * FROM users WHERE user_name='".safe($_SESSION['user_name'])."'") or die ("Cannot find table"); while( $cred = mysql_fetch_array($r) ) { if ($cred >= '1' ) { ?> <p>You have £<? echo $cred['user_credit']; ?> available on you account, would you like to use it on this order?<br> <label for="credit"></label> <select name="credit" id="credit"> <option value="Y" selected>Yes, use credit</option> <option value="N">No, save credit</option> </select> </p> <? } } ?> Hi all
we have an ajax query which queries a MySQL database for cities around the world for our hotel search. We are running on a Linux web hosted server.
The problem we are having is when you first visit out site and type in Brisbane or Sydney it takes around 15 seconds maybe to return. After that what ever city you query is lightening fast. I have had a few friends try this and when they first visit our site they experience the same then second time around it is fast.
Could this be some sort of caching issue or setting somewhere that I am missing?
I have attached a file so you can see what I mean
Thanks in advance
Attached Files
ajaxqry.jpg 169.31KB
0 downloads hi there alll newbie here lol just needed help with the code for the next page of results ? IE i have say 30 results returned from a sql query but only want to show ten at a time i no how to limit the result with the LIMIT 10 but how do i get it to put link show the other ten and so on. the code i have is here at the bottom of page http://www.phpfreaks.com/forums/index.php/topic,307971.0.html thanks in advance for any help kaine ok, this is clearly 1st grade code for some, but i'm not there yet - I'm querying posts in WordPress, and the post_content will always have an image in the beginning of the post followed by the content. i don't want to get the image, just the content that's after the image, which is wrapped in anchor tags, of course. Code: [Select] <a href="http://path/to/image.jpg"><img src="http://path/to/image.jpg" /></a> <p>Post content yadda, yadda, hoowie</p> obviously a character count won't work, so i need to get anything that follows the first "</a>", say...? is this the best way, or is there an easier way? thanks for anyone's help. GN I tired something earlier, with no luck... so I'm taking a few steps back. I've been working this one complicated page for days... Here's what used to work: Code: [Select] //the current URL $page_name = $_SERVER["REQUEST_URI"]; //remove any old limit from query before requesting a new limit $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'limit') $tmp[] = $fld . '=' . $val; $page_name = $_SERVER['SCRIPT_NAME'] . '?' . implode('&',$tmp); //sets the number of records to be displayed on the page <form> <select name="link"> <option value="<? echo "$page_name" ?>&limit=25">25 records per page</option> <option value="<? echo "$page_name" ?>&limit=50">50 records per page</option> <option value="<? echo "$page_name" ?>&limit=100">100 records per page</option> </select> </form> This grabs the current URL, and clears the &limit= string before a new limit is introduced to avoid: www.example.com/test.php?sub=math[]&sub[]=science&limit=25&limit=50&limit=100 The problem, is that my URL is already querying an array: www.example.com/test.php?sub[]=math&sub[]=science So now, when I apply the form above to this URL set the new limit to 50 records per page the URL actually becomes: www.example.com/test.php?sub=Array&limit=50 Warning: Invalid argument supplied for foreach() ... on line 147 I guess I've broken the array? Code: [Select] //line 147 echo "subject:<BR />"; if(!empty($_GET['sub'])) foreach($_GET['sub'] as $sub) { echo "$sub <BR />\n"; } ~Wayne Given the below 3 database tables I am trying to construct a SQL query that will give me the following result: customer_favourites.cust_id customer_favourites.prod_id OR product.id product.code product.product_name product.hidden product_ section.section_id (MUST BE ONLY THE ROW WITH THE LOWEST SECTION ID, I.E. ROW ID #44108) product_ section.catpage (MUST BE ONLY THE ROW WITH THE LOWEST SECTION ID, I.E. ROW ID #44108) product_ section.relative_order (MUST BE ONLY THE ROW WITH THE LOWEST SECTION ID, I.E. ROW ID #44108) I currently have.... SELECT customer_favourites.cust_id, customer_favourites.prod_id, product.code, product.product_name, product.hidden, product_section.section_id, product_section.relative_order, product_section.catpage FROM customer _favourites INNER JOIN product ON customer_favourites.prod_id = product.id INNER JOIN product_section ON product_section.product_code = product.code WHERE `cust_id` = '17' AND `hidden` = '0' GROUP BY `code` ORDER BY `section_id` ASC, `relative_order` ASC, `catpage` ASC LIMIT 0,30 This gives me what I want but only sometimes, at other times it randomly selects any row from the product_section table. I was hoping that by having the row I want as the last row (most recent added) in the product_section table then it would select that row by default but it is not consistent. Somehow, I need to be able to specify which row to return in the product_section table, it needs to be the row with the lowest section_id value or it should by the last row (most recent). Pulling my hair out so any help is gratefully received. customer_favourites id cust_id prod_id 70 4 469 product id code product_name hidden 469 ABC123 My Product 0 product_section id section_id catpage product_code relative_order recommended 44105 19 232 ABC123 260 1 44106 3 125 ABC123 87 1 44107 2 98 ABC123 128 1 44108 1 156 ABC123 58 0 Hi, I am trying to create a view where the user can sort by any column. What I have made so far works great, but when it comes to pagination, which I will be trying soon, I foresee a problem . The thing is, my code gets data out of a database and puts it into a multidimensional array, which is sorted using afew array sorting functions. It is a query that drives the main loop, and inside that loop are other queries that get various data from other tables, which is where the problem lies when coming to sort with pagination. What I would like to know is how would I build a myslq query that can accomplish the same thing as my code, but do away with the need for the arrays? My code is here, sorry about it being so long: <?PHP if($_POST['targetid']) { $box = array() ; if($_POST['type']) { $extra = 'AND entity_details.typeRef = ?' ; $targetType = $_POST['type'] ; } $sortMode = $_POST['sortmode'] ; $targetUser = $_POST['targetid'] ; include('pdoconnect.php') ; $result = $dbh->prepare("SELECT entity_details.name, entity_contacts.name AS cName, entity_contacts.id, entity_details.countryRef FROM entity_details, entity_contacts WHERE entity_contacts.isPrimary = 1 AND entity_contacts.entityRef = entity_details.id $extra AND entity_details.ownerRef = ?") ; if($extra) { $result->bindParam(1, $targetType, PDO::PARAM_INT) ; $result->bindParam(2, $targetUser, PDO::PARAM_INT) ; } else $result->bindParam(1, $targetUser, PDO::PARAM_INT) ; $result->execute() ; $count = $result->rowCount() ; if($count > 0) { echo "Showing " ; if($targetType == 2) echo "prospects!" ; elseif($targetType == 3) echo "customers!" ; elseif($targetType == 4) echo "leads!" ; else echo "everything." ; echo '<br />' ; } if($count > 0) { $mode = $_GET['sort'] ; echo "<div class='row'>\n" ; echo "<div class='cell'>" ; if($sortMode != 'name') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'name');\">Name</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrname');\">Name</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'contact') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'contact');\">Contact</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcontact');\">Contact</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'email') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'email');\">Email</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rremail');\">Email</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'tel') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'tel');\">Tel</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrtel');\">Tel</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'payment') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'payment');\">Payment Terms</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrpayment');\">Payment Terms</a>" ; echo "</div>" ; echo "<div class='cell' style='width:30px;'>" ; if($sortMode != 'currency') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'currency');\">Cur</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcurrency');\">Cur</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'country') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'country');\">Country</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcountry');\">Country</a>" ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; if($sortMode != 'lastc') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'lastc');\">Last Contacted</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrlastc');\">Last Contacted</a>" ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; if($sortMode != 'lastm') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'lastm');\">Last Marketed</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrlastm');\">Last Marketed</a>" ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; if($sortMode != 'lastd') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'lastd');\">Last Deal</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrlastd');\">Last Deal</a>" ; echo "</div>" ; echo "<div class='cell' style='width:50px;'>" ; if($sortMode != 'cltv') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'cltv');\">CLTV</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcltv');\">CLTV</a>" ; echo "</div>" ; echo "</div>\n" ; } else { echo "You have no " ; if($targetType == 2) echo "prospects!" ; elseif($targetType == 3) echo "customers!" ; elseif($targetType == 4) echo "leads!" ; else echo "nothing!" ; } while($row = $result->fetch(PDO::FETCH_ASSOC)) { $id = $row['id'] ; $countryid = $row['countryRef'] ; // Get primary contact data. $resultName = $dbh->prepare("SELECT entity_contacts_emails.email, entity_contacts_telephones.tel FROM entity_contacts_emails, entity_contacts_telephones WHERE entity_contacts_emails.contactRef = ? AND entity_contacts_telephones.contactRef = ? LIMIT 1") ; $resultName->bindParam(1, $id, PDO::PARAM_INT) ; $resultName->bindParam(2, $id, PDO::PARAM_INT) ; $resultName->execute() ; $rowName = $resultName->fetch(PDO::FETCH_ASSOC) ; /////////////////////////// // Get country. $resultCountry = $dbh->prepare("SELECT country FROM countries WHERE id = ? LIMIT 1") ; $resultCountry->bindParam(1, $countryid, PDO::PARAM_INT) ; $resultCountry->execute() ; $rowCountry = $resultCountry->fetchColumn() ; /////////////////////////// // Get currencies dealt with. $resultCurrencies = $dbh->prepare("SELECT currencies.symbol FROM entity_currencies_dealt, currencies WHERE entity_currencies_dealt.currencyRef = currencies.id AND entity_currencies_dealt.entityRef = ?") ; $resultCurrencies->bindParam(1, $id, PDO::PARAM_INT) ; $resultCurrencies->execute() ; while($rowCurrencies = $resultCurrencies->fetch(PDO::FETCH_ASSOC)) { $currencyString .= $rowCurrencies['symbol'] . " " ; } /////////////////////////// // Get payment terms. $resultTerms = $dbh->prepare("SELECT entity_payment_terms.term FROM entity_details, entity_payment_terms WHERE entity_details.paymentTermsRef = entity_payment_terms.id AND entity_details.id = ?") ; $resultTerms->bindParam(1, $id, PDO::PARAM_INT) ; $resultTerms->execute() ; $resultTerms = $resultTerms->fetchColumn() ; /////////////////////////// // Get last contacted. $resultLastCon = $dbh->prepare("SELECT DATE(date) FROM contact_method_history WHERE id = ? ORDER BY date LIMIT 1") ; $resultLastCon->bindParam(1, $id, PDO::PARAM_INT) ; $resultLastCon->execute() ; $resultLastCon = $resultLastCon->fetchColumn() ; /////////////////////////// // Get last enquired. $resultLastEnq = $dbh->prepare("SELECT DATE(dateCreated) FROM entity_enquiries WHERE entityRef = ? ORDER BY DATE(dateCreated) LIMIT 1") ; $resultLastEnq->bindParam(1, $id, PDO::PARAM_INT) ; $resultLastEnq->execute() ; $resultLastEnq = $resultLastEnq->fetchColumn() ; /////////////////////////// array_push($box, array(rawurldecode($row['name']), rawurldecode($row['cName']), $rowName['email'], $rowName['tel'], $resultTerms, trim($currencyString), $rowCountry, $resultLastCon, $resultLastEnq)) ; $currencyString = '' ; } } $i = 0 ; function subval_sort($a, $subkey, $mode) { foreach($a as $k=>$v) { $b[$k] = strtolower($v[$subkey]); } if(strstr($mode, 'Rr')) arsort($b); else asort($b); foreach($b as $key=>$val) { $c[] = $a[$key]; } return $c; } if($sortMode == 'name' || $sortMode == 'Rrname') $x = 0 ; if($sortMode == 'contact' || $sortMode == 'Rrcontact') $x = 1 ; if($sortMode == 'email' || $sortMode == 'Rremail') $x = 2 ; if($sortMode == 'tel' || $sortMode == 'Rrtel') $x = 3 ; if($sortMode == 'payment' || $sortMode == 'Rrpayment') $x = 4 ; if($sortMode == 'currency' || $sortMode == 'Rrcurrency') $x = 5 ; if($sortMode == 'country' || $sortMode == 'Rrcountry') $x = 6 ; if($sortMode == 'lastc' || $sortMode == 'Rrlastc') $x = 7 ; if($sortMode == 'laste' || $sortMode == 'Rrlaste') $x = 8 ; if($count > 0) $box = subval_sort($box, $x, $sortMode); foreach($box as $row) { echo "<div class='row'>\n" ; echo "<div class='cell'>" ; echo $row[0] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[1] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[2] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[3] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[4] ; echo "</div>" ; echo "<div class='cell' style='width:30px;'>" ; echo $row[5] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[6] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[7] ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; echo $row[8] ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; echo $row[9] ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; echo $row[10] ; echo "</div>" ; echo "<div class='cell' style='width:50px;'>" ; echo $row[11] ; echo "</div>" ; echo "</div>\n" ; } ?> I know maybe it can be done using many subqueries(?) but I am pretty average at MySQL. Can anyone tell me how? SELECT field, (array of values from table 2) FROM $table1 t1 LEFT JOIN $table2 ON t1.id=t2.id ... is something like this possible? (where I return records from t1 in a LEFT JOIN, but also get an array of any of the fields/records from the table 2) Hi
I have a table i populate from database (upon a parameter the user insert and with PHP $_GET i take this value and populate the table accordint to if). After I allow the user to add or edit data in rows by using jquery. The last part I do is to want to save the changes back to database using PHP. The jquery i use suppose to serve different tables. So its written in a way that get the table structure and add rows upon it. In this example I put it in the index page Everything works fine,but I cant build the array from the added rows. My variables in the php part got null values (although in debug mode I see that $_POST... store data in the array What do I miss here? Thanks here is my php+ html part of index,php <?php require_once("../xxx/Includes/GlDbOra.php"); if(isset($_POST['submit_btn'])) { $catalog_id=$_GET['catalog_id']; $tableRow = $_POST['tableRow']; foreach ($tableRow as $row) { $item_id=$row['ITEM_ID']; $item_name=$row['ITEM_NAME']; $userid=$_SESSION['userid']; $program='PHP'; $stid=DBOracle::getInstance()->insert_items($catalog_id, $item_id, $item_name, $userid, $program); } } if (!empty($_GET['catalog_id'])) { $catalog_id=trim($_GET['catalog_id']); $catalog_id_desc=$_GET['catalog_id_desc']; $stid=DBOracle::getInstance()->get_items($catalog_id); } ?> <html> <head> <meta charset="UTF-8"> <title>Items</title> <script type="text/javascript" src="../../Bundles/php-ajax/jquery-3.5.1.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script> <script type="text/javascript" src="../../Bundles/bootstrap-4.5.0-dist/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> <link href="../../Bundles/bootstrap-4.5.0-dist/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <link href="../xxx/css/global_style.css" type="text/css" rel="stylesheet" madia="all"/> </head> <body> <div id="page-wrap"> <section id="main-content"> <div id="guts"> <span style="clear: both; float: left; margin-left: 5%;"> <form id="param_form" name="populate_table" method="GET" action="index.php"> <label for="catalog_id">Catalog Id</label> <input type="text" name="catalog_id" class="catalog_id" id="left_radius_textbox" value=" <?php echo htmlspecialchars($catalog_id, ENT_QUOTES); ?>" placeholder="<?php echo catalog_id; ?>"/> <input type="text" name="catalog_id_desc" class="catalog_id_desc" id="right_radius_textbox" value=" <?php echo htmlspecialchars($catalog_id_desc, ENT_QUOTES); ?>" readonly /> <button class="load_form"><span class="glyphicon glyphicon-refresh"></span> Get Data</button> </form> </span> <br> <div class="container"> <div class="row"> <div class="panel panel-primary filterable"> <div class="panel-heading"> <h3 class="panel-title">Items</h3> <div class="pull-right"> <button class="btn btn-default btn-xs btn-filter"><span class="glyphicon glyphicon-filter"></span> Filter</button> </div> </div> <form id="form" name="form1" method="POST" action=""> <table class="table table-fixed" id="tab_logic"> <thead> <tr class="filters" id ="table_header_2_btn"> <th class="col-xs-2"><input type="text" name="tableRow[0]['ITEM_ID']" value="" placeholder="Item Id" disabled></th> <th class="col-xs-6"><input type="text" name="tableRow[0]['ITEM_NAME']" value="" placeholder="Description" disabled></th> <th class="col-xs-4"></th> </tr> </thead> <tbody> <?php $catalog_id=$_GET['catalog_id']; $count=0; while ($row= oci_fetch_array($stid, OCI_ASSOC)): echo "<tr>"; echo "<td class=".'"col-xs-2"><input name="tableRow['.$count.']['."'ITEM_ID']".'"'.' value="'.htmlspecialchars($row['ITEM_ID'], ENT_QUOTES).'" style='."'border:none;".'></td>"'; echo "<td class=".'"col-xs-6"><input name="tableRow['.$count.']['."'ITEM_NAME']".'">'.htmlspecialchars($row['ITEM_NAME'], ENT_QUOTES)."</td>"; $count++; ?> <td class="col-xs-4"> <a class="add" title="Add" data-toggle="tooltip"><i class="material-icons"></i></a> <a class="edit" title="Edit" data-toggle="tooltip"><i class="material-icons"></i></a> <a class="delete" title="Delete" data-toggle="tooltip"><i class="material-icons"></i></a> </td> <?php echo "</tr>\n"; endwhile; oci_free_statement($stid); oci_close($con); ?> </tbody> <tr> <button class="regular_button" id="add-new"><span class="glyphicon glyphicon-plus"></span> Add Rows</button> <td><input type="submit" name="submit_btn" value="Submit"></td> </tr> </table> </form> </div> </div> </div> </div> </section> </div> <script> </script> </body> </html> and here is the jquery part in the index.php (that in between the <script></script>) $(document.body).on('click', '#add-new', function() { $('[data-toggle="tooltip"]').tooltip(); var actions = $("#tab_logic td:last-child").html(); $(this).attr("disabled", "disabled"); var index = $("#tab_logic tbody tr:last-child").index(); var newRow = $("<tr>"); var cols = ""; var element_string=''; var table_structure = $('#table_header_2_btn')[0].innerHTML; table_structure=$.trim(table_structure); var arrStr = table_structure.split(/\n/g); for(var i=0; i<arrStr.length-1; i++) { arrStr[i] =$.trim(arrStr[i]); element_string=arrStr[i]; if (element_string.indexOf('<th')!=-1) { var n=element_string.indexOf('<th'); element_string='<td'+ element_string.substr(n+3); var n=element_string.indexOf('[0]'); element_string= element_string.substr(0,n)+'['+index+']'+element_string.substr(n+3); } if (element_string.indexOf('placeholder=')!=-1) { var n=element_string.indexOf('placeholder='); element_string=element_string.substr(0,n-1); element_string=element_string + '</td>'; } cols+=element_string; } cols+='<td class="col-xs-4">' + actions + '</td>' cols +='</tr>'; newRow.append(cols); $('#tab_logic').append(newRow); $("#tab_logic tbody tr").eq(index + 1).find(".add, .edit").toggle(); $('[data-toggle="tooltip"]').tooltip(); }); $(document).on("click", ".add", function() { var empty = false; var input = $(this).parents("tr").find('input[type="text"]'); input.each(function() { if(!$(this).val()) { $(this).addClass("error"); empty = true; } else { $(this).removeClass("error"); } }); $(this).parents("tr").find(".error").first().focus(); if(!empty) { input.each(function() { // $(this).parent("td").html($(this).val()); }); $(this).parents("tr").find(".add, .edit").toggle(); $("#add-new").removeAttr("disabled"); } }); $(document).on("click", ".edit", function() { $(this).parents("tr").find("td:not(:last-child)").each(function() { $(this).html('<input type="text" value="' + $(this).text() + '">'); }); $(this).parents("tr").find(".add, .edit").toggle(); $("#add-new").attr("disabled", "disabled"); }); $(document).on("click", ".delete", function() { $(this).parents("tr").remove(); $("#add-new").removeAttr("disabled"); });
Below is the code I have so far for only 2 terms with '$word" being the keyword of the site and all the other words are suppose to be linked if they appear in the text. Okay I have thousands of different possible words from the same table. In the table 'word' is the term to be defined and 'definition' is the main content. I want a code that recognizes any word that is listed in my table and replaces it. <?php $find2 = array ('/$word/i', '/bond/i'); $replace2 = array ('<a href=http://www.subjectmoney.com/definitiondisplay.php?word=$word><b>$word</b></a>', '<a href=http://www.subjectmoney.com/definitiondisplay.php?word=Bond>bond</a>'); Echo preg_replace ($find2, $replace2, $definition); ?> In my form I have this: Code: [Select] <div class="confSub {conferences.confClass}"> <div> <input type="hidden" name="confPK" value="{conferences.confPK}"> <label>Conference Attended:</label><input size="85" name="conference[{conferences.confCounter}]" type="text" value="{conferences.conference}"/> <label>Date:</label><input size="20" name="confDate[{conferences.confCounter}]" type="text" value="{conferences.confDate}"/> <span class="example left"> ( YYYY-MM-DD )</span> <label class="fullLabel clearfix">Description and Benefit to the University:</label> <textarea name="confDesc[{conferences.confCounter}]" cols="90" rows="5">{conferences.confDesc}</textarea> <input class="checkbox clearfix" name="confPres[{conferences.confCounter}]" value="yes" type="checkbox" {conferences.checkedConf}/> <label class="midLabel">Conference Presentation?</label> <label class="clearfix">Title of Presentation:</label> <input class="pushLeft" size="85" name="confPresTitle[{conferences.confCounter}]" type="text" value="{conferences.ConfPresTitle}"/> </div> </div> I need to take the values of the same index for eachof five arrays ($_POST['conference'], $_POST['confDate'], $_POST['confDesc'], etc...) and insert/update them into a mysql table. So conference[0], confDate[0], confDesc[0], confPres[0], and confPresTitle[0] all need to go into the same index of their respective fields in the DB table. If it was one array I could just do something like: foreach($_POST['conference'] as $conference) { // Update Conference $degreeQuery = "UPDATE CONFERENCES SET Conference = '".$conference."', StaffPK1 = '".$getPK1."' WHERE ConferencePK1 ='".$confID."'"; $degreeQuery = mysql_query($degreeQuery); } I'm having trouble with how to add a value from each array into the sql table. I could do it through a different foreach loop for each array and iterate through all foreach loops with another loop, but that doesn't seem very efficient. I'd like to do it with one sql statement for each set of "conference" data. Thanks in advance, Shannon for starters, i am a complete beginner at PHP, so i know almost nothing.
so, the basic outline is that i am required to create a table with 2 columns, and use PHP where i can
so the first set of code lays down the table and the ability to type in text of "name" and "surname". ----i think this "input" is HTML, yes?? is there a way to enter it as PHP?
<table border=\"2\"> <tr><th><b>Requirements</b></th><th><b>Selections</b></th></tr> <tr><td>Name</td><td><input type="text" name="name"/></td></tr> <tr><td>Surname</td><td><input type="text" name="surname"/></td></tr>so, for this next section, adding on is the part for "age". i want this to appear as a dropdown selection. i've written PHP where possible, however this does not work when opening the file in a browser. it simply leaves a blank dropdown menu with no options. ???? <tr><td>Age</td><td><select> <?php for ($num=11; $num<=22; $num++){ echo '<option>' .$num. '</option>'; } ?> </select>lastly, i have the part for "activity choice". this again i believe i wrote the radio buttons in HTML??? am i able to write this as PHP???? <tr><td>Activity Choice</td><td><input type="radio" name="activityChoice" value "music"/> Music ($30.00)<br> <input type="radio" name="activityChoice" value "swimming"/> Swimming ($25.50)<br> <input type="radio" name="activityChoice" value "tennis"/> Tennis ($20.00)<br> <input type="radio" name="activityChoice" value "basketball"/> Basketball ($15.50)<br> <input type="radio" name="activityChoice" value "netball"/> Netball ($15.50)<br> <input type="radio" name="activityChoice" value "dance"/> Dance ($10.50)<br> <input type="radio" name="activityChoice" value "communityService"/> Community Service (No Charge)</td></tr> Hi Guys, I have a query and a while loop output that I am sending to a webpage in a table format but I need some help in how best to do this so that the table columns line up with each other. Right now the column width seems to change depending on the data in the row. The code is quite simple: <?php include("lib/config.php"); $query = "SELECT * FROM staff_member"; $result = mysql_query($query); ?> <html> <style type="text/css"> <!-- @import url(style/style.css); --> </style> <head> </head> <body> <h2 align="center"> Full Staff list with Dependants</font></h2> <?php while($row = mysql_fetch_object($result)) { echo "<table id=sample> <th>Title</th> <th>First Name</th> <th>Initial</th> <th>Last</th> <th>Agency</th> <th>Street</th> <th>Address</th> <th>Parish</th> <th>Country</th> <th>Office Tel#</th> <th>Home Tel#</th> <th>Office Mobile#</th> <th>Personal Mobile#</th> <th>Zone</th> <th>Status</th> <th>Location</th> <th>Updated by</th> <tr> <td>" .$row->title ."</td> <td>" .$row->first ."</td> <td>" .$row->initial ."</td> <td>" .$row->last ."</td> <td>" .$row->agency ."</td> <td>" .$row->street ."</td> <td>" .$row->adress ."</td> <td>" .$row->parish ."</td> <td>" .$row->country ."</td> <td>" .$row->officetel ."</td> <td>" .$row->hometel ."</td> <td>" .$row->officemobile ."</td> <td>" .$row->personalmobile ."</td> <td>" .$row->zone ."</td> <td>" .$row->status ."</td> <td>" .$row->location ."</td> <td>" .$row->updater ."</td> </tr>"; echo "</table> </br>"; }//close $row while ?> </body> </html> Any help appreciated! Hi guys, I need your help! I have two tables "sp_users" and "sp_schools" in the same database. Now I want to add column "time" from "sp_schools" to a phpfile which displays "sp_users". The column "time" should be after column "update". I made it upto here, but to get the second query and display Please help. I am devastated... Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY user_id"; $result=mysql_query($sql); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000033; } .style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #003333; } --> </style> <title>User overview</title><table width="486" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="427"> <div align="left"> <table width="486" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta Users </strong></div></td> </tr> <tr> <td width="26" align="center"><span class="style2">id</span></td> <td width="70" align="center"><span class="style2">Name</span></td> <td width="114" align="center"><span class="style2">Lastname</span></td> <td width="146" align="center"><span class="style2">Email</span></td> <td width="88" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style8"><? echo $rows['user_id']; ?></span></td> <td><span class="style8"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style8"><? echo $rows['user_surname']; ?></span></td> <td><span class="style8"><? echo $rows['user_login']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style8">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="center"> <?php mysql_close(); ?> </div> Hello
We have a database table that confirms the installations started and completed for our game... and I am looking to confirm how many installs start but never complete...
So, this is my current query...
SELECT description, ip from error_log where description like '%install%' order by ip; I'm having trouble with the logic for my query. Printing $sql gives me the following: SELECT r.id,r.created,r.firstname,r.lastname,r.address1,r.city,r.state,r.zip,r.phone,r.email,r.comments,Error: 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 'BBQ' at line 1 "BBQ" is the first $val from the loop. What am I missing? Code: [Select] $sql = "SELECT r.id,r.created,r.firstname,r.lastname,r.address1,r.city,r.state,r.zip,r.phone,r.email,r.comments,"; $dbQuery = mysql_result(mysql_query("SELECT description FROM events"), 0,0); $size = count($dbQuery); $i = 0; foreach ($dbQuery as $val) { //02 if($val != '') { //02 $sql .= "MAX(CASE e.description WHEN '". $val ."' THEN e.description END) AS `". $val ."`"; } $i++; if($i != $size) $sql .= ","; }//02 if (!mysql_query($dbQuery)) { die('Error: ' . mysql_error()); } $sql .= "FROM requests r LEFT OUTER JOIN ( registration_xref xref INNER JOIN events e ON e.id_events = xref.event_id ) ON r.id = xref.attendee_id GROUP BY r.id"; |