Topic awaiting preservation: Is this possible in PHP and MySQL? (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: Norway |
posted 01-24-2008 14:43
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 |
posted 01-24-2008 15:13
Yes, this is possible, |
Bipolar (III) Inmate From: Norway |
posted 01-24-2008 15:27
But a new job will hold lots of information. Like if my job is called 20080101 and I write: |
Bipolar (III) Inmate From: Norway |
posted 01-24-2008 16:00
Never mind, I get it now, lol! Thanks you so much! |
Maniac (V) Inmate From: there...no..there..... |
posted 01-24-2008 16:04
quote:
|
Bipolar (III) Inmate From: Norway |
posted 01-24-2008 16:53
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 |
posted 01-24-2008 17:36
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 |
posted 01-24-2008 17:50
Thank you! Bookmarked this thread. I really hope I can get everything the way I want it. |
Paranoid (IV) Inmate From: Madison, Indiana |
posted 01-24-2008 20:47 |
Bipolar (III) Inmate From: Norway |
posted 01-24-2008 21:28
Hi! It's been a while since I've been here. I'm a carpenter now and make furniture. But I really want to get back to web design and start posting here again. I bet this place is still as cool as it was years ago! |
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 01-24-2008 23:02
hey... I'll be building a bar soon |
Bipolar (III) Inmate From: Norway |
posted 01-24-2008 23:24
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 |
posted 01-26-2008 21:24
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? |
posted 01-26-2008 22:58
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 |
posted 01-26-2008 23:19
Thank you! I'll try that. |
Bipolar (III) Inmate From: Curled up with a ... ...warm laptop? |
posted 01-27-2008 00:49
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 |
posted 01-27-2008 02:00
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 |
posted 01-27-2008 13:19
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 |
posted 01-27-2008 13:44
I was actually quite surprised to see it myself when I posted, hehe! "Oh, my squirrel is still here!!" |
Paranoid (IV) Inmate From: Norway |
posted 01-27-2008 14:03 |
Bipolar (III) Inmate From: Norway |
posted 01-27-2008 14:55
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 |
posted 01-27-2008 18:36
no, you don't create a new table for each customer . |
Bipolar (III) Inmate From: Norway |
posted 01-27-2008 19:20
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 |
posted 01-28-2008 23:18
Okay, I'm back! I've made 3 tables called bestillinger (orders), sprosser (window frames) and kunder (customers). 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 |
posted 01-29-2008 09:42
php->mysql_insert_id() is what you're looking for. |
Bipolar (III) Inmate From: Norway |
posted 01-29-2008 12:15
Thanks! It works! Now all I have to do is figure out how to show the ordernumber the way I want. I've been working on the code I got above, and it shows the year and day + 1 like this: 2008011. But it shows up like that in every new row and it won't count the order id. Here's the code I'm using: 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 |
posted 01-29-2008 12:59
Because you're writing the first query with like '200801' insteod of like '200801%'. |
Bipolar (III) Inmate From: Norway |
posted 01-29-2008 13:36
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 |
posted 01-29-2008 14:01
php->strpad will do what you need. |
Bipolar (III) Inmate From: Norway |
posted 01-29-2008 14:16
Ah! That will work even better than the way I did it. |
Bipolar (III) Inmate From: Norway |
posted 01-30-2008 00:21
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 |
posted 01-30-2008 04:22
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 |
posted 01-30-2008 11:31
That fixed it! I now have a page with the new orders showing. I'm going to work with what I have before doing anything more. I really appreciate all the help from you guys and I've learned a lot! |
Paranoid (IV) Inmate From: Florida |
posted 01-31-2008 00:24
quote:
|