Jump to content

piznac

Members
  • Posts

    261
  • Joined

  • Last visited

Everything posted by piznac

  1. ok,.. that should work,. wow always something simple..LOL.. Thanks man., Let me give this a go. I don't want to mark it as solved untill I can place the code up though
  2. Yeah I was looking at that,.. but dosent that return the number for the last one? What if I inserted like 100 at a time? Would that just return the last one. I would need the numbers from all 100.
  3. I suppose I could do a query before the insert to see what is the last auto number. Then count the number of inserts and add one to each (incrementally) and then use those numbers. This seems highly inaccurate though,.. is there a better way?
  4. Prehaps this is a backwards way of doing this. So if Im being dense please don't hesitate to say so. So here is what I have: function insert_multi($item_num,$item_desc,$item_qty,$emb_loc1,$num,$size,$artwork){ $flds = array( 'item_num' , 'item_desc' , 'item_qty', 'num', 'size'); for($i=0;$i<count($_POST['item_qty']);$i++) { $qtmp = array(); foreach($flds as $fld) if (trim(stripslashes($_POST[$fld][$i])) != '') $qtmp[] = $fld . " = '" . mysql_escape_string(trim(stripslashes($_POST[$fld][$i]))) . "'"; $q = "insert into c_or_details set " . implode(', ',$qtmp); $rs = mysql_query($q) or die ('Problem with 1 the query: ' . $q . '<br>' . mysql_error()); } } As you can see Im inserting an indermined amount of records into a mysql table. Next I need to insert the remaining data "$artwork & $emb_loc1" into another table. Which dosent really pose a problem. But with each entry of the last sql statement an auto increment value defines each entry. I need that auto number to insert with the other data into the new table. Does that make sense. Basically I have a main table and a sub table. The main table holds the main data on an order. The sub table holds "options" of the order. But to be able to pull them back I need a primary key to match the key in the main table. Anyone know an easy way to get this data from the first table to the other?
  5. Ok,.. mark this one as solved. Turns out this was a mysql error and not the fgetcsv as the error message eluded to. This is the final code,.. please if any one see any problems with this let me know. And thanks for the help Barrand,.. I still owe you that beer..lol: <?php $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } $filenameb= $base . $filename; if (file_exists($filenameb)){ echo "$filenameb</br>"; $handle = fopen("$filenameb", "r") or die("no file"); while (($data = fgetcsv($handle, 50000, "," )) !== FALSE ){ $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','') ON DUPLICATE KEY UPDATE ship_date = values(ship_date), ship_via = values(ship_via), job_name = values(job_name), job_desc = values(job_desc), finishing = values(finishing), po_num = values(po_num), cust_name = values(cust_name), tracking = values(tracking), pro_date = values(pro_date)"; mysql_query($import) or die("insert" . mysql_error()); } fclose($handle); echo "Import Done"; }else{ echo "Import Unsuccessful"; } ?>
  6. ok when I take this out: while (($data = fgetcsv($handle, 50000, "," )) !== FALSE ){ $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','')ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name);"; mysql_query($import) or die("insert" . mysql_error()); fclose($handle); echo "Import Done"; } and leave just this: <?php $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } $filenameb= $base . $filename; if (file_exists($filenameb)){ echo "$filenameb</br>"; $handle = fopen("$filenameb", "r") or die("no go"); $data = fgetcsv($handle, 50000, "," ); }else{ echo "No way hose"; } ?> I dont get the error,. this is just strange. Or to narrow it down even further,. I dont get the error when I take this out: ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name)"; Is there an easier way to do this?
  7. the file is there,.. or the fopen would have died on me I assume. Funny thing is earlier today I had this working. But then I got to messing with the sql connections and all (all removed) and it hasent functioned since. BTW do you know what the 7 in the error represents?
  8. Ok permissions look good. And I tried that but Im getting the same error. I might have changed something else in the process,.. here is what I have <?php require_once('sew.php'); require_once('sew.php'); $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } $filenameb= $base . $filename; if (file_exists($filenameb)) { echo "$filenameb</br>"; $handle = fopen("$filenameb", "r") or die("no go"); while (($data = fgetcsv($handle, 50000, "," )) !== FALSE ){ $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','')ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name);"; mysql_query($import) or die("insert" . mysql_error()); fclose($handle); print "Import done"; } }else{ echo "No way hose"; } ?> Wait,.. one sec ,.. yep still the same thing
  9. It looks good with the dir "/var/www/html/ups/" 755 & the dir the script is in being 777. Quite stumped on this one Oh wait I think you were saying the root?... let me have a look at that.
  10. Can someone tell me what the 6 means here: "Warning: fgetcsv(): 6 " cause now Im getting 7
  11. Ok I had this working earlier,.. but wanted to update as well. And now things seem to have gotten screwed up. Any help would be appreciated.:: <?php $base = "/var/www/html/ups/"; $filename = $_FILES['file']['name']; echo $filename; if (@is_uploaded_file($_FILES["file"]["tmp_name"])) { copy($_FILES["file"]["tmp_name"], "$base" . "$filename"); } if (isset($filename)) { $filenameb= "$base" . "$filename"; echo $filenameb; $handle = fopen($filenameb, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT INTO orders(`or_date`,`ship_date`,`ship_via`,`job_name`,`job_desc`,`finishing`,`or_num`,`po_num`,`cust_name`,`tracking`,`pro_date`) values('$data[0]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[1]','$data[2]','$data[3]','','')ON DUPLICATE KEY UPDATE ship_date = VALUES(ship_date),ship_via = VALUES(ship_via),job_name = VALUES(job_name),job_desc = VALUES(job_desc),finishing = VALUES(finishing),po_num = (po_num),cust_name = VALUES(cust_name);"; mysql_query($import) or die("insert" . mysql_error()); fclose($handle); print "Import done"; } }else{ echo "No way hose"; } ?> This is the error Im getting: Warning: fgetcsv(): 6 is not a valid stream resource in /var/www/html/control/up.php on line 84 Now the file is there and is a csv, seperated by a comma. I dont get it.
  12. hmmm,.. ok sounds logical to me thanks for the help!
  13. Ahh yes,.. indeed I did. Sorry dude,.. trying to go to fast. Thanks! But Im not seeing what else was wrong. Do the mysql_select_db or fetch_assoc really matter that much if they are duplicated? Would it make the script fail,.. or is there something else i misssed? Thanks
  14. Now Im only getting the last record.... :-\ mysql_select_db($database_pro, $pro); $query_user = sprintf("SELECT * FROM `users_fish` WHERE `c_num` = '$c'"); $user = mysql_query($query_user, $pro) or die(mysql_error()); $row_user = mysql_fetch_assoc($user); $totalRows_user = mysql_num_rows($user); mysql_select_db($database_pro, $pro); $query_order = sprintf("SELECT * FROM `fishy_cart` WHERE `cookieId` = '$c'"); $order = mysql_query($query_order, $pro) or die(mysql_error()); $row_order = mysql_fetch_assoc($order); $totalRows_order = mysql_num_rows($order); $u_num = $row_user['u_num']; $u_name = $row_user['name']; $order_num0 = date("mdy"); $order_num = "$order_num0$row_user[u_num]"; while ($row_order = mysql_fetch_assoc($order)) { $i_num = $row_order['i_num']; $s_name = $row_order['s_name']; $price = $row_order['price']; $quanity = $row_order['quanity']; $lot = $row_order['lot']; mysql_select_db($database_pro, $pro); $insert_sql = "INSERT INTO `itsfishy_products`.`fishy_ordata` (`user_id`, `user_name`, `order_id`, `item_num`, `item_name`, `item_price`, `item_qty`, `lot_price`) VALUES ('$u_num', '$u_name', '$order_num', '$i_num', '$s_name', '$price', '$quanity ', '$lot') "; $doit = mysql_query($insert_sql, $pro) or die(mysql_error()); }
  15. Ok thanks,.. I'll give that a go.
  16. thanks,.. but nah the table structures are not exactly the same.
  17. I believe you will need two pages. One to have the form where the user enters the number. Then the form action will take you to the next page via a submit button. Then you can use the $_POST[] var to pull your query.
  18. Ok,.. seems Im having problems with another loop. I want to take a number of lines from one table in the DB and insert them into another. Please tell me if there is an easier way to do this. I didn't think it would be any big deal but something is not right. mysql_select_db($database_pro, $pro); $query_user = sprintf("SELECT * FROM `users_fish` WHERE `c_num` = '$c'"); $user = mysql_query($query_user, $pro) or die(mysql_error()); $row_user = mysql_fetch_assoc($user); $totalRows_user = mysql_num_rows($user); mysql_select_db($database_pro, $pro); $query_order = sprintf("SELECT * FROM `fishy_cart` WHERE `cookieId` = '$c'"); $order = mysql_query($query_order, $pro) or die(mysql_error()); $row_order = mysql_fetch_assoc($order); $totalRows_order = mysql_num_rows($order); $u_num = $row_user['u_num']; $u_name = $row_user['name']; $order_num0 = date("mdy"); $order_num = "$order_num0$row_user[u_num]"; for($i=0;$i<count($row_order['i_num']);$i++) { $i_num = $row_order['i_num']; $s_name = $row_order['s_name']; $price = $row_order['price'][$i]; $quanity = $row_order['quanity'][$i]; $lot = $row_order['lot'][$i]; mysql_select_db($database_pro, $pro); $insert_sql = "INSERT INTO `itsfishy_products`.`fishy_ordata` (`user_id`, `user_name`, `order_id`, `item_num`, `item_name`, `item_price`, `item_qty`, `lot_price`) VALUES ('$u_num', '$u_name', '$order_num', '$i_num', '$s_name', '$price', '$quanity ', '$lot') "; $doit = mysql_query($insert_sql, $pro) or die(mysql_error()); } It seems Im only getting the first record. There I suppose the loop isnt working the way I planned. I always seem to have issues with these d$#@ loops. Should I use a foreach loop inside the for loop? Or am I way off track? BTW all the SQL statements seem to be working fine as I have them echo'ing on other parts of the page.
  19. Thank you once again Barand,.. one of these days Im gonna get you that beer
  20. Ok thanks I will look into this when I get home. I think I get it,.. thanks!
  21. Ok,.. I know I have seen this asked before. But after many searches and browsing the first ten pages here I am. This should be fairly simple though: Say I have an image database with image path & image name. Now normally I would do something like while(blah = blah){ echo "<tr><td>$row['path']</td><td>$row['name']</td></tr>"; } or something like that,. kinda in a rush here (at work and this has nothing to do with any work related projects .. lol) Now that would output something like this: 1.path | name 2.path | name 3.path | name 4.path | name etc.... what I would like is: 1.path | name 2.path | name 3.path | name 4.path | name any help? Sorry if this was rushed. If it dosent make any sense I will redo it tonight. Thanks!
  22. Ok Im a dummy,.. lol ;D [code]$projects_array[] = $row_store['pog_type'];[/code] the colum name is pogtype not pog_type Thanks for all the help!!!!!
  23. well I tried something there,. but changed it back. Also it is now working but not display the "pog_types" just the commas. EDIT Yeah I just changed that but still the same this is what I have: [code]<?php require_once('../../Connections/conner.php'); $dm = $_GET['dm']; mysql_select_db($database_conner, $conner); $query_dmstore = "SELECT * FROM dmrmst"; $dmstore = mysql_query($query_dmstore, $conner) or die(mysql_error()); $totalRows_dmstore = mysql_num_rows($dmstore);         echo "Total number of stores: ". $totalRows_dmstore ."<br />\n"; while($row_dmstore = mysql_fetch_array($dmstore)){ $query_store = "SELECT * FROM pog_check WHERE storenum = ". $row_dmstore['store'] .""; $store = mysql_query($query_store, $conner) or die(mysql_error());                 $projects_array = array(); //<--- you can reset it here while($row_store = mysql_fetch_array($store)){ $projects_array[] = $row_store['pog_type']; } $string = implode(", ", $projects_array); echo "Store#". $row_dmstore['store'] ." = ". $string ."<br />\n";                 unset($projects_array);  //<---- OR you can reset it here. } ?>[/code]
×
×
  • 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.