![]() Topic awaiting preservation: Is this possible in PHP and MySQL? (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: Norway |
![]() Hi! I'm not sure if PHP and MySQL is what I need to be able to create a database to use at work. |
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() Yes, this is possible, |
Bipolar (III) Inmate From: Norway |
![]() But a new job will hold lots of information. Like if my job is called 20080101 and I write: |
Bipolar (III) Inmate From: Norway |
![]() Never mind, I get it now, lol! Thanks you so much! |
Maniac (V) Inmate From: there...no..there..... |
![]() quote:
|
Bipolar (III) Inmate From: Norway |
![]() Thank you. I have another question. Is it possible for me to output everything into a table on a webpage and take maybe the value of width, add the number 5 to it and output that to a different cell in the table? These might be stupid questions, but I'm a newbie. :/ |
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() Sure. Either do it in php, or simply get the databse to do it... code: $hRes = mysql_query('select *, width + five as "with_plus_five" from your_table order by orderNo'); print '<table>'; while ($arrRow = mysql_fetch_array($hRes)) { print '<tr>'; foreach ( $arrRow as $strField) { print '<td>'. $strField .'</td>'; } print '</tr>; } print '</table>';
|
Bipolar (III) Inmate From: Norway |
![]() Thank you! Bookmarked this thread. |
Paranoid (IV) Inmate From: Madison, Indiana |
![]() |
Bipolar (III) Inmate From: Norway |
![]() Hi! It's been a while since I've been here. I'm a carpenter now and make furniture. |
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() hey... I'll be building a bar soon |
Bipolar (III) Inmate From: Norway |
![]() If you have any questions, I'll do my best to help. We should probably open a new woodworking forum in here... |
Bipolar (III) Inmate From: Norway |
![]() Okay, I've been working on this and have come across a problem. When I'm going to add a new job to the database, I want it to automatically add the date (I've figured out how to do this). But I don't want the whole date, just the year and month: 2008-01. I want the next number to be the order number for that month. Like if I add 5 jobs in January, the whole order number for those jobs would be: |
Bipolar (III) Inmate From: Curled up with a ... ...warm laptop? |
![]() id -- unsigned int (auto_increment, primary key) code: // This gets the number of orders starting with "2008-01-..." $order_number = date("Y-m-"); $query = "SELECT `id` FROM `orders` WHERE `ordernumber` LIKE '" . $order_number . "';"; // The number of rows we find are the number of orders we've had this month. // Add one to this, as it will be the next order. $num_orders_this_month = mysql_num_rows(mysql_query($query)); $order_number .= ($num_orders_this_month + 1); // $order_number = "2008-01-5" or something like that // You can use a zerofill function to make it 2008-01-05 if you want. $query = "INSERT INTO `job_queue` VALUES('', NOW(), '" . $order_number . "', ... mysql_query($query);
|
Bipolar (III) Inmate From: Norway |
![]() Thank you! I'll try that. |
Bipolar (III) Inmate From: Curled up with a ... ...warm laptop? |
![]() Make sure you know what the code's doing though, and how it can be handled better. Both PHP and MySQL have excellent online documentation. |
Bipolar (III) Inmate From: Norway |
![]() I'm still learning PHP and MySQL and I think working on a project like this is fun while learning it. I do have a question about the code above. Do I have to create a new table called 'job_queue'? Is it not possible to store the ordernumber in 'orders'? Thanks |
Maniac (V) Mad Librarian From: Seoul, Korea |
![]() I have absolutely nothing to add to this topic, except: long time no see, fenja! I missed the little squirrel. |
Bipolar (III) Inmate From: Norway |
![]() I was actually quite surprised to see it myself when I posted, hehe! "Oh, my squirrel is still here!!" |
Paranoid (IV) Inmate From: Norway |
![]() |
Bipolar (III) Inmate From: Norway |
![]() I have another question. Should I create a table for each customer/firm? We have 3-4 big firms that we produce window frames to. (not sure if window frames is the correct word in English..) When I add a new huge order to the customer 'Remi', is it best to create a table for him and store all his orders in there? I think one of my problems is figuring out what structure I should use for my database. |
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() no, you don't create a new table for each customer |
Bipolar (III) Inmate From: Norway |
![]() ah, I see! That should keep me busy for a while. I'm going make a test database and see if I can get everything to work. Thank you! |
Bipolar (III) Inmate From: Norway |
![]() Okay, I'm back! code: $query ="SELECT kunder.navn, bestillinger.orderid, bestillinger.dato, sprosser.type, sprosser.antall FROM kunder, sprosser, bestillinger WHERE (kunder.kid = bestillinger.kid)";
code: $query = "INSERT INTO sprosser VALUES ('$sid','$antall','$bredde','$hoyde','$malenr','$type','$rutb','$ruth','$merk')"; mysql_query($query); $query = "INSERT INTO bestillinger VALUES ('', NOW(), '$orderid', '$sid','2')"; mysql_query($query);
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() php->mysql_insert_id() is what you're looking for. |
Bipolar (III) Inmate From: Norway |
![]() Thanks! It works! code: $order_number = date("Ym"); $query = "SELECT bestillinger.id FROM bestillinger WHERE bestillinger.orderid LIKE '" . $order_number . "'"; $num_orders_this_month = mysql_num_rows(mysql_query($query)); $order_number .= ($num_orders_this_month + 1); $query = "INSERT INTO bestillinger(id, dato, orderid, sid, kid) VALUES ('', NOW(), '" . $order_number . "', '$sid','2')";
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() Because you're writing the first query with like '200801' insteod of like '200801%'. |
Bipolar (III) Inmate From: Norway |
![]() I got the first code to work by changing it a little: code: $order_number = date("Ym"); $query = "SELECT bestillinger.id FROM bestillinger"; $num_orders_this_month = mysql_num_rows(mysql_query($query)); $order_number .= ($num_orders_this_month+1);
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() php->strpad will do what you need. |
Bipolar (III) Inmate From: Norway |
![]() Ah! That will work even better than the way I did it. |
Bipolar (III) Inmate From: Norway |
![]() Hmm...I'm stuck again. How can I show all the orders from one specific customer? I thought the code I posted earlier worked, but I only had one order in the database. When I added 3 more orders, it showed the 4 orders 4 times. Here's the code again: code: $query ="SELECT kunder.navn, bestillinger.orderid, bestillinger.dato, sprosser.type, sprosser.antall FROM kunder, sprosser, bestillinger WHERE (kunder.kid = bestillinger.kid)"; $result=mysql_query($query); $num=mysql_numrows($result);
|
Paranoid (IV) Inmate From: Madison, Indiana |
![]() Change code: FROM kunder, sprosser, bestillinger WHERE (kunder.kid = bestillinger.kid)
code: FROM bestillinger LEFT OUTER JOIN kunder ON (kunder.kid = bestillinger.kid) LEFT OUTER JOIN sprosser ON ( sprosser.sid = bestillinger.sid)
|
Bipolar (III) Inmate From: Norway |
![]() That fixed it! |
Paranoid (IV) Inmate From: Florida |
![]() quote:
|