PHP - Problem Returning Array In Correct Format
I have a script that runs a query against a MySQL database, then, if it returns a resultset, it takes the 'freindly name from an array containg the database connections, then adds the data for the resultset.
Unfortunately at the minute, it doesn't quite work the way that I want. So far I have: //get list of servers to query, and choose them one at a time for($a = 0; $a <sizeof($slaveRes_array); $a++) { $con = mysql_connect($slaveRes_array[$a]['server'], $slaveRes_array[$a]['user'], $slaveRes_array[$a]['password']); mysql_select_db($dbs, $con); //get list of MySQL Queries, and run them against the current server, one at a time for($b = 0; $b <sizeof($query_array); $b++) { $SlaveState = mysql_query($query_array[$b]['query1'], $con); // 1st Query // If there is a resultset, get data and put into array while($row = mysql_fetch_assoc($SlaveState)) { for($c = 0; $c <mysql_num_rows($SlaveState); $c++) { $slave_array[]['name'] = $slaveRes_array[$a]['database']; for($d = 0; $d <mysql_num_fields($SlaveState); $d++) { $slave_array[][mysql_field_name($SlaveState,$d)] = mysql_result($SlaveState,$c,mysql_field_name($SlaveState,$d)); }} } } // Run Query2...Query3....etc. } The problem is that at the minute it puts each field into a separate part of the array e.g. Array ( => Array ( [name] => MySQL02_5083 ) [1] => Array ( [Slave_IO_State] => Waiting for master to send event ) [2] => Array ( [Master_Host] => localhost ) [3] => Array ( [Master_User] => root ) Whereas what I am trying to achieve is more like: Array ( => Array ( [name] => MySQL02 ) [Slave_IO_State] => Waiting for master to send event ) [Master_Host] => localhost ) [Master_User] => root )... [1] => Array ( [name] => MySQL03 etc. etc. But I can't see how to achieve this? Similar TutorialsI am currently trying to make a baseball database with player statistics for each particular game. The page as of now looks something like this: Opponent #1 Player #1 Player #2 Player #7 Opponent #2 Player #1 Player #2 Player #5 and this goes on. When I click on Player #1 under Opponent #1 I get the correct stats. However when I click on Player #1 under Opponent #2 I get the same stats as if I was clicking Player #1 under Opponent #1. Here is the coding for the content page: Code: [Select] <?php require_once("includes/functions.php"); ?> <?php if (isset($_GET['gm'])) { $sel_gm = get_game_by_id($_GET['gm']); $sel_player = NULL; } elseif (isset($_GET['player'])) { $sel_gm = NULL; $sel_player = get_player_by_id($_GET['player'], $sel_gm); } else { $sel_gm = NULL; $sel_player = NULL; } ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php $game_set = get_all_games(); while ($game = mysql_fetch_array($game_set)) { echo "<li"; if ($game["Game_ID"] == $sel_gm) { echo " class=\"selected\""; } echo "><a href=\"content.php?gm=" . urlencode($game["Game_ID"]) . "\">{$game["Opponent"]}</a></li>"; $player_set = get_players_for_game($game["Game_ID"]); echo "<ul class=\"pages\">"; while ($player = mysql_fetch_array($player_set)){ echo "<li"; if ($player["Player_ID"] == $sel_player) { echo " class=\"selected\""; } echo "><a href=\"content.php?player=" . urlencode($player["Player_ID"]) . "\">{$player["First"]}" . " " . "{$player["Last"]}</a></li>"; } echo "</ul>"; } ?> </ul> </td> <td id="page"> <?php if (!is_null($sel_gm)) { // game selected ?> <h2><?php echo $sel_gm['Opponent']; ?></h2> <?php echo $sel_gm['Game_ID']; ?> <?php } elseif (!is_null($sel_player)) { // player selected ?> <h2><?php echo "{$sel_player['First']}" . " " . "{$sel_player['Last']}"; ?></h2> <div class="page-content"> <h3><?php echo $sel_player['Opponent']. "<br />" . " " ?></h3> <?php echo "PA: " . $sel_player['PA'] . "<br />" . " AB: " . $sel_player['AB']. "<br />" . " H: " . $sel_player['H'] . "<br />" . " HR: " . $sel_player['HR']. "<br />" . " RBI: " . $sel_player['RBI'] . "<br />" . " BB: " . $sel_player['BB']. "<br />" . " Runs: " . $sel_player['Runs'] . "<br />" . " SAC: " . $sel_player['SAC']. "<br />" . " ROE: " . $sel_player['ROE'] . "<br />" . " 1b: " . $sel_player['1b']. "<br />" . " 2b: " . $sel_player['2b'] . "<br />" . " 3b: " . $sel_player['3b']. "<br />" . " TB: " . $sel_player['TB'] . "<br />" . " SO: " . $sel_player['SO']. "<br />" . " GIDP: " . $sel_player['GIDP'] . "<br />" . " SB: " . $sel_player['SB']. "<br />" . " CS: " . $sel_player['CS']; ?> </div> <?php } else { // nothing selected ?> <h2>Select a game or player to edit</h2> <?php } ?> </td> </tr> </table> <?php require("includes/footer.php"); ?> And Here is the coding for the functions: Code: [Select] <?php function confirm_query($result_set) { if (!$result_set) { die("Database query failed:" . mysql_error()); } } function get_all_games() { global $connection; $query = "SELECT * "; $query .= "FROM offense "; $query .= "LEFT JOIN players ON offense.Player_ID = players.Player_ID "; $query .= "LEFT JOIN game ON offense.Game_ID = game.Game_ID "; $query .= "ORDER BY players.Player_ID ASC "; $query .= "LIMIT 1"; $game_set = mysql_query($query, $connection); confirm_query($game_set); return $game_set; } function get_players_for_game($Game_ID) { global $connection; $query = "SELECT players.*, offense.* FROM players INNER JOIN offense ON players.Player_ID = offense.Player_ID WHERE Game_ID = {$Game_ID} ORDER BY players.Player_ID ASC"; $player_set = mysql_query($query, $connection); confirm_query($player_set); return $player_set; } function get_game_by_id($Game_ID) { global $connection; $query = "SELECT game.*, offense.* "; $query .= "FROM game "; $query .= "INNER JOIN offense ON game.Game_ID = offense.Game_ID "; $query .= "WHERE offense.Game_ID=" . $Game_ID . " "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if($game = mysql_fetch_array($result_set)) { return $game; } else { return NULL; } } function get_player_by_id($sel_player, $sel_gm) { global $connection; $query = "SELECT * "; $query .= "FROM offense "; $query .= "INNER JOIN players ON offense.Player_ID = players.Player_ID "; $query .= "INNER JOIN game ON offense.Game_ID = game.Game_ID "; $query .= "WHERE offense.Player_ID =" . $sel_player . " "; $query .= "AND offense.Game_ID =" . $sel_gm . " "; $query .= "ORDER BY players.Player_ID ASC "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if($player = mysql_fetch_array($result_set)) { return $player; } else { return NULL; } } ?> My 5 tables in my database a defense: Player_ID, Game_ID, (this also has all of the stats for defense) game: Game_ID, Opponent, Game_Date offense: Player_ID, Game_ID, (this also has all of the stats for offense) pitching: Player_ID, Game_ID, (this also has all of the stats for pitching) players: Player_ID, First, Last Any help would be greatly appreciated. Thank You Hi all, I am working on my PHP script to set up the date with the time for the autoresponder so I can send out the emails at the specific time. I need some help with set up the correct day date with the time, because on my code when I have two different times `06:00` and `20:00`, as both of them will show the time with the current day date, e.g: 28-11-2019. I find that my code have set up the date as incorrect because the time I have `06:00` which it should have set up with the next day date, e.g 29-11-2019 instead of 28-11-2019 and the time `20:00` should set up with the current day date as my current time is `15:26pm` right now.
2019-11-25 06:00
06:00
$auto_responders = $link->prepare('SELECT * FROM autoresponder WHERE campaign = ? ORDER BY id ASC'); $auto_responders->execute([$campaign]); $auto_responders->setFetchMode(PDO::FETCH_ASSOC); $auto_responders = $auto_responders->fetch(PDO::FETCH_ASSOC); $get_time = $auto_responders['send_time']; if ($get_time >= strtotime('00:00')) { $autoresponder_date = date('Y-m-d', strtotime($get_time . ' +1 day')); } else { $autoresponder_date = date('Y-m-d', strtotime($get_time)); } $send_time = $autoresponder_date . ' '. date('H:i ', strtotime($get_time));
Can you please show me an example how I can set up the day date for the time `06:00` and `20:00` as if I have the time is `06:00` then check if the time have passed before I could do anything to send the email and it is the same for the time `20:00:00`? Thank you.
I have the following query: $getVideos = mysql_query("SELECT catergory, COUNT(catergory) as 'catCount' FROM videos GROUP BY catergory"); Using this in PHPMyAdmin returns the correct results of: catergory | catCount 0 | 7 1 | 1 10 | 2 How would get those results into a PHP array or what not...I have done this before but along time ago and cannot for the life of me remember how to do it. Hopefully someone can point me in the right direction? Regards, PaulRyan. Hey there, Now I was curious if there was a way I could return an array in my function like the following, I currently get a error though: Code: [Select] Catchable fatal error: Object of class panel_accounts could not be converted to string in C:\wamp\www\X-HostLTD - Panel\PanelFrontend\index.php on line 21 But can you only return strings?. Here is the function that it errors on: function returnAccountInformation($AccountID) { return mysql_fetch_array(mysql_query("SELECT * FROM ****_***** WHERE *****_***** = '".mysql_escape_string($AccountID)."'")); } Could somebody help me on the matter?, Thank you. P.S sorry for staring out the table names but I don't really want people knowing my database structure hehe. Trying to retun an array which gets a file from a directory and then returns the filename as the key and the complete file url as the value but when returning it it prints out "Array" for each file in the directory rather than the file name: Doing this in wordpress. Code: [Select] function wsme_select_css_theme(){ $alt_css_template_path = WSME_THEME_CSS; // Define path to files $alt_widgets_template = array(); // set array $out = ''; // Set var if ( is_dir($alt_css_template_path) ) { // If directory exists if ($alt_css_template_dir = opendir($alt_css_template_path) ) { //opens directory while ( ($alt_css_template_file = readdir($alt_css_template_dir)) !== false ) { //if files are in the directory if(stristr($alt_css_template_file, ".css") !== false) { //if the files are .css files $out[] = array($alt_css_template_file => WSME_THEME_CSS.'/'.$alt_css_template_file); //create the array(filename => file path) for each file in the directory } } } return $out; // return array } } Code: [Select] array( 'name' => 'Style', 'id' => WS_THEME_PREFIX . '_style', 'headings' => array( array( 'name' => 'Theme CSS', 'options' => array( array('name' => 'Homepage', 'desc' => ' select the css file of the theme you want for your site', 'id' => WS_THEME_PREFIX . '_theme_css', 'value' => '', 'options' => wsme_select_css_theme(), 'type' => 'select' ) ) ) ) Any suggestions? Hey Guys, I am hoping you can help me find out why a function of mine is only returning 1 record when I am asking for 10. Here is the function I am using to get the data. When I run the $sql that is printed in phpmyadmin.... I get then records. But when I print the $event_data I am only getting 1 record. Any help would be greatly appreciated function get_events($data) { //print_r($data); $lat = $data['lat']; $long = $data['long']; $offset = $data['offset']; $radius = $data['radius']; $amount = $data['amount']; //the events query $sql = sprintf("SELECT *, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM events WHERE `status` = '0' HAVING distance < '%s' ORDER BY distance LIMIT $amount OFFSET $offset", mysql_real_escape_string($lat), mysql_real_escape_string($long), mysql_real_escape_string($lat), mysql_real_escape_string($radius)); //debugging print_r($sql); $event_data = array(); $event_data = mysql_fetch_array(mysql_query($sql)); //debugging print_r($event_data); return $event_data; } Hi, A piece of software I'm using an array is made that looks like the following: Code: [Select] [["Select","Vehicle",0.142933,[0.15,0.4,0.05,0.01]]] How would I be best parsing it so: Square brackets currently showing an array becomes an array within PHP Text strings surrounded by "quotations" lose the quotation mark when stored in the PHP array Numbers remain as values in the PHP array The arrays can become quite large, so which would be the best way to go about it? Regards, Jason Hi Guys, I have 6 file upload fileds in an array. When i try to return the error messages at this link: http://www.php.net/manual/en/features.file-upload.errors.php i get an error displayed for every upload box. I was wondering if it is possible to simply return 1 error instead of the 6? For example rather than getting "No File Uploaded No File Uploaded No File Uploaded No File Uploaded No File Uploaded No File Uploaded" i simply get "No File Uploaded". Also If only some files are uploaded no error should be displayed. The code i am using is: foreach ($_FILES['image']['error'] as $key => $error) { if ($error == UPLOAD_ERR_NO_FILE) { echo "No File Uploaded"; } I have tried using "break;" which works in leaving only 1 error, however the error is still displayed if less than 6 files are uploaded. All help greatly appreciated. Thanks Hi fellow developers, I'm having a real problem at the moment, I'm trying to capture everything in between <body></body> tags using the following code but it does not print anything: $lines = file("http://www.bbc.co.uk/"); foreach ($lines as $line_num => $line) { $thecontent .= htmlspecialchars($line) . "<br />\n"; } preg_match('/<body.*?>(.*?)<\/body >/', $thecontent, $htmltext); $moretext = $htmltext[1]; echo $moretext; When you do place a "print($thecontent);" into the code the entire html for [whatever the website] does display but I want to capture only the html code in between the body tags. I've tried everything but I just can't get this to work. I would appreciate anyone's help and I'd like to thank you in advance. M Hi guys, I am using this oAuth library https://github.com/elbunce/oauth2-php But more specifically these lines of code: protected function getToken($token, $isRefresh = true) { try { $tableName = $isRefresh ? self::TABLE_REFRESH : self::TABLE_TOKENS; $tokenName = $isRefresh ? 'refresh_token' : 'oauth_token'; $sql = "SELECT $tokenName, client_id, expires, scope, user_id FROM $tableName WHERE token = :token"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':token', $token, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result !== FALSE ? $result : NULL; } catch (PDOException $e) { $this->handleException($e); } } However, this is retuning no value. If I modify the code to be: protected function getToken($token, $isRefresh = true) { return $token; } It returns the $token value, so the $token is definitely being passed to the function. The code should return an associative array: i.e., $token["expires"], $token["client_id"], $token["userd_id"], $token["scope"], etc Also $token should not === NULL. PS. I run a few checks on $tableName = $isRefresh ? self::TABLE_REFRESH : self::TABLE_TOKENS; $tokenName = $isRefresh ? 'refresh_token' : 'oauth_token'; And they are returning the correct values. Which from my thinking narrows it down to: $sql = "SELECT $tokenName, client_id, expires, scope, user_id FROM $tableName WHERE token = :token"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':token', $token, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result !== FALSE ? $result : NULL; Any and all help is greatly appreciated. Thanks in advance. I am trying to return all the photos in the database that has the albumid associated with that table info. I can echo the $album->id (albumid) no problem, but my query it think is somewhat off. Please anyone. Code: [Select] <div id="photo-items" class="photo-list-item"> <?php echo $album->id.'<br>'; // fetch album photos and ids $database =& JFactory::getDBO(); $query = "SELECT * FROM jos_photos where albumid = ".$album->id." ORDER BY ASC"; $photos = mysql_query($query); //This returns and array of photos, but then needs to display all the photos in loop below, but it not retuning none, even if there is 100 photos in table and in the folder directory if($photos) { for( $i=0; $i<count($photos); $i++ ){ $row =& $photos[$i]; ?> <div class="photo-item" id="photo-<?php echo $i;?>" title="<?php echo $this->escape($row->caption);?>"> <a href="<?php echo $row->link;?>"><img class="" src="<?php echo $row->getThumbURI();?>" alt="<?php echo $this->escape($row->caption);?>" id="photoid-<?php echo $row->id;?>" /></a> <?php if( $isOwner ) { ?> <div class="photo-action"> <a href="javascript:void(0);('<?php echo $row->id;?>');" class="remove"><?php echo JText::_('CC REMOVE');?></a> </div> <?php } ?> </div> <?php } } else { ?> <div class="empty-list"><?php echo JText::_('CC NO PHOTOS UPLOADED YET');?> <button class="button button-upload" href="javascript: void(0);&userid=88" id="upload-photos-button">Start Uploading</button></div> <?php } ?> </div> Originally, I would get both, and unfortunately would inconsistently use both. Then, I wanted more consistently, so configured php.ini to only return objects as I felt accessing them was more concise. And then later, I found myself needing arrays more often, and initially would just typecast them to arrays but eventually my standard was to set the PDO's fetch style to an array. And now I find myself almost always explicitly requesting arrays and occasionally requesting columns or named values. Do you configure ATTR_DEFAULT_FETCH_MODE, and if so to what? PS. Anyone use FETCH_CLASS, FETCH_INTO or FETCH_NUM? If so, what would be a good use case? What is the name for this Array Format... Code: [Select] $resultsArray[] = array('questionID' => $questionID, 'question' => $question, 'answer' => $new_answer, 'DB_answer' => $old_answer, 'message' => $message[$q]); And does this have anything to do with Object-Oriented Programming?! Thanks, Debbie I have my array like so Code: [Select] $inaque = array("'$dir'"=>"'$company'"); When I run Code: [Select] print_r($inaque); It shows like Code: [Select] Array ( ['share_what_you_want'] => 'Share What You Want' ) How can I get this array to print out like Code: [Select] array ( 'share_what_you_want' => 'Share What You Want' ) Without the [ ] This is the format that is needed for this code that has already been written by somebody else. Thanks in advance Is their a way to format lr.submit_time in every record that is returned in the $results array without doing like a for/foreach loop? Like array_walk() or something similar? $query = " SELECT lr.*, l.make, l.model, l.part_number, l.description, pd.job_number, pd.line_item, pd.enterprise, pd.description, pd.qty AS order_qty, log.name AS user_full_name FROM leds_requests lr LEFT JOIN leds l ON l.id = lr.product_id LEFT JOIN production_data pd ON pd.id = lr.order_id LEFT JOIN login log ON log.user_id = lr.user_id WHERE lr.id IN( SELECT MAX(id) FROM leds_requests WHERE status_id = 0 GROUP BY order_id, product_id ) AND lr.id NOT IN( SELECT id FROM leds_requests WHERE lr.id = id AND status_id IN(1, 2, 3, 4) ) GROUP BY order_id, product_id, job_number "; $statement = $pdo->prepare($query); $statement->execute(); $results = $statement->fetchAll(); echo json_encode($results);
Hi I am new to php, I am trying to capture the url and place into a variable but I only get the 1st digit to show, I just cant see what I am doing wrong. Sorry to ask such a basic question but I just can't work it out, I have attached a screen shot of all me code, your help would be very very much appreciated. I had some code that I'm pretty sure used to work, basically something like the below. Code: [Select] if (preg_match("/[a-zA-Z0-9]+/", $_POST['title'])) { echo $_POST['title'];exit(); } Now i just don't get why it always returns true, even when entering special characters like "!#%?".. The only thing which comes to mind, is that i recently made a move to UTF-8.. I'm currently looping on an array with this structu Categories{ CategoryName CategoryCode CategoryDescription Products{ product_info{ product_code product_type{ CountNumber ProductDescription } } prices{ "wholesale":"250", "retail":"400" } } }
I'm looping on the above array at each level, and I've declared an array so that I can put all my needed values into it $priceResult = array(); foreach($prices->categories as $category){ $categoryName = $category->category_name; $categoryCode = $category->category_code; $categoryDescription = $category->category_desc; foreach($category->products as $product){ foreach($product->product_info as $info){ $product_code = $info->product_code; foreach($info->product_type as $type){ $CountNumber = $type->CountNumber; $ProductDescription = $type->ProductDescription; } } foreach ($product->prices as $price => $amount) { $price_amount = $amount; } } } The problem I'm having is I don't know how to properly push into that new ```$priceResult``` array so that I can use PHPExcel to put it into a format with a subheader. The format I would want from the above example would be something like this
Test Category 1 | 123 | Category for Testing
Test Category 2 | 321 | New Category for Testing So basically I want to call PHPExcel on my $priceResult array in order to get that format where I can list my category info, and for each product within that category, I'd have a product row. Everything would be grouped by the category main header $build = Excel::create($name, function ($excel) use ($priceResult) { $excel->setTitle('Test Products'); UPDATE:
CategoryCode : 123 CategoryName : TestCategory CategoryDescription: For Testing Products{ 0{ Product_code : 123, CountNumber : 12, ProductDescription: Test Product, price_amount : 150.00 }, 1{ Product_code : 112, CountNumber : 32, ProductDescription: Test Product 2, price_amount : 250.00 } }
It's pretty simple to see what I am trying to do here. For some reason all results in the table are the same exact cityName replacing all existing records. The echoed results are correct. I've include a small dump of my table as well. $query = "SELECT cityName FROM sys_city_dev_2"; $resource = mysqli_query($cxn, $query) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query"); while($result = mysqli_fetch_assoc($resource)) { $nox = $result['cityName']; $toUpper = ucfirst($nox); echo "$toUpper" . "<br />"; $setString = "UPDATE sys_city_dev_2 SET cityName = '" . $toUpper ."' WHERE cityName != ''"; mysqli_query($cxn,$setString); } 100 Records of table dump (pre running my script above): -- -- Table structure for table `sys_city_dev_2_backup` -- CREATE TABLE IF NOT EXISTS `sys_city_dev_2_backup` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev_2_backup` -- INSERT INTO `sys_city_dev_2_backup` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'dothan', 0, 0, 0), (84011, 1, 'alabaster', 0, 0, 0), (84012, 1, 'birmingham', 0, 0, 0), (84013, 2, 'flagstaff', 0, 0, 0), (84014, 1, 'auburn', 0, 0, 0), (84015, 1, 'florence', 0, 0, 0), (84016, 1, 'gadsden', 0, 0, 0), (84017, 1, 'huntsville', 0, 0, 0), (84018, 1, 'mobile', 0, 0, 0), (84019, 1, 'montgomery', 0, 0, 0), (84020, 1, 'tuscaloosa', 0, 0, 0), (84021, 2, 'mohave valley', 0, 0, 0), (84022, 2, 'phoenix', 0, 0, 0), (84023, 2, 'prescott', 0, 0, 0), (84024, 2, 'sierra vista', 0, 0, 0), (84025, 2, 'tucson', 0, 0, 0), (84026, 2, 'yuma', 0, 0, 0), (84027, 3, 'bakersfield', 0, 0, 0), (84028, 3, 'chico', 0, 0, 0), (84029, 3, 'fresno / madera', 0, 0, 0), (84030, 3, 'gold country', 0, 0, 0), (84031, 3, 'humboldt county', 0, 0, 0), (84032, 3, 'imperial', 0, 0, 0), (84033, 3, 'inland empire', 0, 0, 0), (84034, 3, 'los angeles', 0, 0, 0), (84035, 3, 'alhambra', 0, 0, 0), (84036, 3, 'merced', 0, 0, 0), (84037, 49, 'fayetteville', 0, 0, 0), (84038, 49, 'fort smith', 0, 0, 0), (84039, 49, 'jonesboro', 0, 0, 0), (84040, 49, 'little rock', 0, 0, 0), (84041, 49, 'arkadelphia', 0, 0, 0), (84042, 49, 'texarkana', 0, 0, 0), (84043, 3, 'modesto', 0, 0, 0), (84044, 3, 'alta sierra', 0, 0, 0), (84045, 3, 'alpine', 0, 0, 0), (84046, 3, 'pedley', 0, 0, 0), (84047, 3, 'redding', 0, 0, 0), (84048, 3, 'alondra park', 0, 0, 0), (84049, 3, 'sacramento', 0, 0, 0), (84050, 4, 'canon city', 0, 0, 0), (84051, 3, 'san luis obispo', 0, 0, 0), (84052, 3, 'santa barbara', 0, 0, 0), (84053, 3, 'stockton', 0, 0, 0), (84054, 3, 'aliso viejo', 0, 0, 0), (84055, 3, 'visalia', 0, 0, 0), (84056, 3, 'yuba city', 0, 0, 0), (84057, 4, 'boulder', 0, 0, 0), (84058, 4, 'colorado springs', 0, 0, 0), (84059, 4, 'denver', 0, 0, 0), (84060, 4, 'applewood', 0, 0, 0), (84061, 4, 'pueblo', 0, 0, 0), (84062, 4, 'air force academy', 0, 0, 0), (84063, 5, 'avon', 0, 0, 0), (84064, 5, 'hartford', 0, 0, 0), (84065, 5, 'new haven', 0, 0, 0), (84066, 5, 'ansonia', 0, 0, 0), (84067, 5, 'fairfield', 0, 0, 0), (84068, 7, 'daytona beach', 0, 0, 0), (84069, 7, 'sebastian', 0, 0, 0), (84070, 5, 'wallingford center', 0, 0, 0), (84071, 8, 'belvedere park', 0, 0, 0), (84072, 7, 'sarasota springs', 0, 0, 0), (84073, 7, 'sandalfoot cove', 0, 0, 0), (84074, 7, 'san carlos park', 0, 0, 0), (84075, 7, 'st. augustine', 0, 0, 0), (84076, 7, 'tallahassee', 0, 0, 0), (84077, 7, 'safety harbor', 0, 0, 0), (84078, 7, 'ruskin', 0, 0, 0), (84079, 8, 'athens-clarke county', 0, 0, 0), (84080, 8, 'atlanta', 0, 0, 0), (84081, 8, 'augusta-richmond county', 0, 0, 0), (84082, 8, 'brunswick', 0, 0, 0), (84083, 8, 'columbus', 0, 0, 0), (84084, 8, 'americus', 0, 0, 0), (84085, 8, 'acworth', 0, 0, 0), (84086, 8, 'valdosta', 0, 0, 0), (84087, 10, 'boise', 0, 0, 0), (84088, 10, 'ammon', 0, 0, 0), (84089, 10, 'moscow', 0, 0, 0), (84090, 10, 'blackfoot', 0, 0, 0), (84091, 10, 'twin falls', 0, 0, 0), (84092, 10, 'meridian', 0, 0, 0), (84093, 10, 'jerome', 0, 0, 0), (84094, 10, 'idaho falls', 0, 0, 0), (84095, 11, 'addison', 0, 0, 0), (84096, 10, 'garden city', 0, 0, 0), (84097, 10, 'eagle', 0, 0, 0), (84098, 10, 'chubbuck', 0, 0, 0), (84099, 10, 'caldwell', 0, 0, 0), (84100, 12, 'bloomington', 0, 0, 0), (84101, 12, 'evansville', 0, 0, 0), (84102, 12, 'fort wayne', 0, 0, 0), (84103, 12, 'indianapolis', 0, 0, 0), (84104, 12, 'muncie / anderson', 0, 0, 0), (84105, 12, 'lafayette / west lafayette', 0, 0, 0), (84106, 12, 'south bend / michiana', 0, 0, 0), (84107, 12, 'terre haute', 0, 0, 0), (84108, 12, 'northwest indiana', 0, 0, 0), (84109, 13, 'ames', 0, 0, 0); Hi.. I have problem in getting the DemandedQty that was input. Only in the Demanded Qty of P28 items was read. For example I input 21 in Demanded Qty of P28 and then It alerts 21, but when I input 2 in Demanded Qty of P30 the alert was 21. It means only the P28 Demanded Qty was get. here is my code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <html> <title>Stock Requisition</title> <head> <link rel="stylesheet" type="text/css" href="kanban.css"> <script type="text/javascript"> function showSum(element) { var clickElement = element.value; var click_id = element.id; var Table = document.getElementById('list'); var rows = Table.rows; var strSelect = document.getElementById(click_id).value; alert(strSelect); // i tried to alert to check if he gets the correct value, but I found that only the Demanded Qty of P28 was read. And when I try to input on another Demanded Qty like in P30 the alert was blank. for (var i = 0; i < rows.length; i++) { var row = rows[i]; if (row.id.substr(0,3) == strSelect) { } } } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div> <table id="list"> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $DemandedQty = $_POST['DemandedQty']; $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); $rowCounter = 1; while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; $Items_ = substr($Items, 12, 3); echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items_[$rowCounter]' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border:none;'> </td> <td style='border:none;'> </td> <td style='border: none;'><center><input type='text' style='text-align: right;' name='DemandedQty[]' id='DemandedQty' value='' size='12' onkeyup ='showSum(this);'></center></td> </tr>"; $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); $rowCounter = 1; while($row_sub = mysql_fetch_assoc($res_sub)){ $Items = $row_sub['Items']; //$Items_ = substr($Items, 12, 3); $SubItems = $row_sub['SubItems']; $ItemCode = $row_sub['ItemCode']; $UoM = $row_sub['UoM']; $Class = $row_sub['Class']; $Description = $row_sub['Description']; $BINLocation = $row_sub['BINLocation']; $Quantity = $row_sub['Quantity']; echo "<input type='hidden' name='Quantity' id='Quantity' value='$Quantity'>"; echo "<tr> <td style='border: none;'> <input type='hidden' value='$Items' id='Items[$rowCounter]' name='Items[]'></td> <td style='border: none;'> <input type='text' name='SubItems[]' value='$SubItems' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'> <input type='text' name='ItemCode[]' value='$ItemCode' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'><center><input type='text' name='SubQty[]' id='SubQty[$rowCounter]' value='' size='12' style='border:none;text-align: right;'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM[]' value='$UoM' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class[]' value='$Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> <td style='border: none;'> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size= '30'></td> <td style='border: none;'> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td> </tr>"; $rowCounter = $rowCounter + 1; } $rowCounter = $rowCounter + 1; } ?> </table> </div> </form> </body> </html> Thank you so much |