Jump to content

frank5050

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Everything posted by frank5050

  1. Hi, I am importing data from a csv file into mysql. Everything works fine except that the 'order_date' column in CSV is in the following format mm/dd/yy. Upon import I would like for that format to be changed to yyyy-mm-dd I am not sure how to modify the following code to be able to do so. Any help would be appreciated. <? include "connect.php"; if(isset($_POST['submit'])) { $filename=$_POST['filename']; $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $date = date("Y-m-d"); $import="INSERT into table (order_id, order_status, order_date, todays_date) values ('$data[0]', '$data[1]', '$data[2]', '$date')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; } else { print "<form action='importnew.php' method='post'>"; print "Type file name to import:<br>"; print "<input type='text' name='filename' size='20'><br>"; print "<input type='submit' name='submit' value='submit'></form>"; } ?>
  2. I altered the second code like this: if(isset($_POST['cbox'])) { foreach($_POST['id'] as $key => $id) { if(isset($_POST['cbox'][$key])) { $checked[] = $id; } else { $unchecked[] = $id; } } if(is_array($checked)) { mysql_query("UPDATE om SET item_shipped = 1 WHERE myID IN (".implode(',', $checked).")"); } if(is_array($unchecked)) { mysql_query("UPDATE om SET item_shipped = 0 WHERE myID IN (".implode(',', $unchecked).")"); } } Still no luck. Checkbox value doesn't get recorded.
  3. Thank you for a fast response: When I copied and pasted : $i = 0; //loop { echo "<input type=checkbox name=cbox[$i] value='1' $chk>"; echo "<input type=hidden name=id[$i] value='$myID' $chk>"; $i++; //} in my form page, it displays checkboxes and their current states fine. For the second step when I copied/pasted the remaining 2 pieces of code one by one in the update.php page. For code: if(isset($_POST['cbox'])) { foreach($_POST['id'] as $key => $id) { if(isset($_POST['cbox'][$key])) { $value = 1; } else { $value = 0; } mysql_query("UPDATE om SET item_shipped = $value WHERE myID=$id"); } } I get the error: Warning: implode() [function.implode]: Invalid arguments passed in /home/dndm/public_html/cms/update.php on line 53 For the second code: if(isset($_POST['cbox'])) { foreach($_POST['id'] as $key => $id) { if(isset($_POST['cbox'][$key])) { $checked[] = $id; } else { $unchecked[] = $id; } } mysql_query("UPDATE om SET item_shipped = 1 WHERE myID IN (".implode(',', $checked).")"); mysql_query("UPDATE om SET item_shipped = 0 WHERE myID IN (".implode(',', $unchecked).")"); } I get the error: Warning: implode() [function.implode]: Invalid arguments passed in /home/dndmobil/public_html/cms/updateom.php on line 53 What gives?
  4. Hi I have an array of checkboxes whose values if checked can be updated in mysql. The code I have below accomplishes that just fine. On my form I have: print "<form method='post' action='update.php'>\n"; /////// mysQL query here $myID = $itemRow['myID']; $chk = $itemRow['item_shipped'] == 1 ? 'checked' : ''; echo "<input type=checkbox name=cbox[] value='{$itemRow['myID']}' $chk>"; echo"</form>"; The above code displays various items with a checkbox next to them. So if that checkbox is checked the code below stores that in mysql. On my update.php page I have: if(sizeof($_POST['cbox'])) { //means if at least one check box is selected foreach($_POST['cbox'] AS $id) { mysql_query("UPDATE om SET item_shipped ='1' WHERE myID=$id"); } //end foreach } //end IF The problem is though i can check a checkbox and store that value '1' in mysql, I have no way of unchecking an already checked checkbox and storing the '0' in mysql. Can anyone help? Thanks in advance
  5. Ok guys newbie here and stumped. I am trying to update a field 'item_shipped' in mySQL if a checkbox is checked and I've run into a checkbox (1 or 0) update problem. I have attached an image with my post so anyone can get a visual idea of how the checkboxes are laid out (customer info is blanked out). Here is structure of the table to give you an idea of the table fields. CREATE TABLE IF NOT EXISTS `om` ( `myID` int(11) NOT NULL auto_increment, `order_id` varchar(50) NOT NULL, `order_status` varchar(50) NOT NULL, `product_name` varchar(10) NOT NULL, `item_shipped` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`myID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=534 ; I have two queries on the form page and both mySQL queries seems to be working ok. The first query outputs order related info which is then used in the second query to iterate results (line items) from individual orders. Given below is the second query that includes checkbox field output, outputting a checkboxe per item on the fly. $itemData = mysql_query('SELECT * FROM om WHERE order_id = ' . $row2['order_id']); while ( $itemRow = mysql_fetch_assoc( $itemData ) ) { $myID = $itemRow['myID']; $chk = $itemRow['item_shipped'] == 1 ? 'checked' : ''; print "<input type='hidden' name='myID[$i]' value='{$itemRow['myID']}' />"; echo "<input type='checkbox' name='$myID' id=box[] value='item_shipped[$i]' $chk>"; echo"<b>{$itemRow['product_name']}</b>"; } <input type=\"submit\" value=\"Submit2\"> </form> So with the help of the above code I have a series of checkboxe printed out which for each item displays 'checked' if the 'item_shipped' field is 1 in the database. Since an order can have multiple items associated and hence a checkbox next to each item, what I want to be able to do is to be able to update the item_shipped field (via checkbox) for multiple items at the same time. I already have an update.php page that updates the order_status and works just fine. I would like to add the functionality of updating the checkbox as well (while updating the order status) In other words, use just one submit button to update order_status (as it currently does), but also add code (possibly another query?) to update the checkbox. I'm very much a newbie and would like someone to help me with the code for the checkbox array update. update.php code is shown below: <? $date = date("Y-m-d G:i:s") ; /* connection information */ $hostname = "localhost"; $username = "xxxx"; $password = "xxxx"; $dbName = "xxxx"; /* make connection to database */ MYSQL_CONNECT($hostname, $username, $password) OR DIE( "Unable to connect to database"); @mysql_select_db("$dbName") or die( "Unable to select database"); // find out how many records there are to update $size = count($_POST['order_status']); // start a loop in order to update each record $i = 0; while ($i < $size) { // define each variable $order_status= $_POST['order_status'][$i]; $order_id = $_POST['order_id'][$i]; // do the update and print out some info just to provide some visual feedback $query = "UPDATE om SET order_status = '$order_status' WHERE order_id = '$order_id'"; mysql_query($query) or die ("Error in query: $query"); print "<font size=2 face=arial><font color=0000FF><b>$order_status</b></font> Updated for Order ID #$order_id</font><br />"; ++$i; } mysql_close(); ?> Thanks in advance. [attachment deleted by admin]
  6. Hello guys, I have 2 tables in my mySQL database. One table stores the customer info and the other table stores the products they ordered. "Order_ID" is the common variable in both tables. I have written a join query which pulls data from both tables. My query looks like this: $query = "SELECT c.*, p.Product_SKU from csm c, csmproducts p where c.Order_ID = p.Order_ID and c.Order_Status='Awaiting Fulfillment' group by Order_ID order by Order_ID DESC LIMIT $startrow, 50"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); } The trouble I am having is that I can query the database for a particular Order_ID, but if that Order_ID has multiple products in it , only the first product is showing. What do I need to do such that where {$row['Product_SKU']} gives me only the first product, I can pull all the Product_SKUs for that particular Order_ID. Currently the output looks like this (showing just the first item the customer orderd) Order ID: Product SKU 5558 DSC-3433 I would like to see it like this: Order ID: Product SKU 5558 DSC-3433 ASD-6454 UFY-7383 5559 ...................... on and on and on for next orders Thanks in advance for the assistance.
  7. I am not sure how else I could simplify my scenario, because what I explained is exactly what I am faced with. Also, I tried to be quite detailed with my questions/explanation. Any help?
  8. Hi, Given below is the output of a field from a mySQL/php query: Product ID: 8457, Product Qty: 3, Product SKU: M-242, Product Name: DCE/DTE DB60 Crossover Cable - 1FT, Product Weight: 1, Product Variation Details: , Product Unit Price: 4.68, Product Total Price: 14.04|Product ID: 8800, Product Qty: 1, Product SKU: M-1038, Product Name: RJ45 8P8C Plug Flat Stranded 50pcs/Bag, Product Weight: 1, Product Variation Details: , Product Unit Price: 3.42, Product Total Price: 3.42|Product ID: 8940, Product Qty: 1, Product SKU: M-1385, Product Name: RJ11/12/45 Crimp Tool with Ratchet [HT-568R], Product Weight: 1, Product Variation Details: , Product Unit Price: 9.89, Product Total Price: 9.89 How can I add a <br> before every occurance of the term "Product" (without quotes). That would make the output legible. Should it be done client side, or server side. I can use help for both. Thanks in advance
  9. Hi PHP/mySQL Gurus, Newbie here, barely know enough to get around. I am importing data into mySQL from a CSV file. The data consists of various fields involving customer information and the products they ordered. All the information pertaining to the customers is easily importable since most of the information is in separate columns of the cSV file and I created a column for each item in my database table and imported the customer information. The hard part is importing the "products" that each customer orders. Given below is the information contatined in "1" column of the CSV file called Product_Details. AS an example: A customer placed a particular order# 4755. The customer ordered 3 different products (and a total of 5 items), the Product_Details column that I need to import into mysql table includes the following info: Product ID: 8457, Product Qty: 3, Product SKU: M-242, Product Name: DCE/DTE DB60 Crossover Cable - 1FT, Product Weight: 1, Product Variation Details: , Product Unit Price: 4.68, Product Total Price: 14.04|Product ID: 8800, Product Qty: 1, Product SKU: M-1038, Product Name: RJ45 8P8C Plug Flat Stranded 50pcs/Bag, Product Weight: 1, Product Variation Details: , Product Unit Price: 3.42, Product Total Price: 3.42|Product ID: 8940, Product Qty: 1, Product SKU: M-1385, Product Name: RJ11/12/45 Crimp Tool with Ratchet [HT-568R], Product Weight: 1, Product Variation Details: , Product Unit Price: 9.89, Product Total Price: 9.89 Few observations in the above data: Each attribute is separate by a comma. Each item ordered by the customer is separated with a "|". Where I need help: 1- Most importantly: How do I import the above data in a table so that I am able to search each order and individual attributes (Product ID, Product Qty, Products SKU, Product Name, Product Weight, Product Variation Details, Product Unit Price, Product Total Price). Should they all reside in separate columns? 2- Since I have already created a table called 'customers' where I have imported customer related info (not the products they ordered). I am thinking (please let me know if I'm thinking correctly or not) that I create a separate table for just the products, where I import the Order ID (4755 in the above example) and Product_Details. Then join queries could be written as needed? would it make more sense to reside just the product related info in a separated table instead? All help is appreciated. Thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.