Jump to content

poleposters

Members
  • Posts

    244
  • Joined

  • Last visited

    Never

Everything posted by poleposters

  1. Also, if it makes it any easier. I'll be filtering the initial array in the sql query to remove peaches & pears etc.
  2. After a day of studying the code above I've finally figured out how it all works. But now I've encountered a new problem. How could I modify the code to allow me to store some information about each piece of fruit? e.g red apple, green apple, yellow banana This would not affect the way the fruit is sorted into bowls. A red or green apple could go into the bowl interchangeably. I would just like to be able to access the bowl array to determine whether the apple is green or red. Thanks!
  3. That's perfect thank you! I'm excited to study it and try and understand how it works. Arrays still boggle my mind. Thank you for your help.
  4. Sorry, I should of mentioned that. I want ignore pears and peaches. Where there is not enough fruit for a complete bowl. I'd like a NULL value in place of the missing fruit.
  5. Hi, I need some help getting my head around arrays. I have a basket of fruit: $basket=("Apple","$Orange","$Banana","$Banana","$Peach","$Apple","$Banana","$Orange","$Apple"); I want to distribute and share this basket of fruit into bowls, such that each bowl contains the following: $bowl=("$Apple",$Orange,"$Banana","$Banana") ie. One Apple, One Orange & Two Bananas. I can't seem to figure out how to do it. Thanks in advance.
  6. Hi, I have items A, B & C that belong to a bundle/kit. These items don't always arrive together in the same shipment. I want to be able to determine the soonest availability of each kit. I have an inventory table that looks like this. (One item per row. Shipment is usually a date. I've used integers to simplify the example) ITEMSHIPMENT A1 C1 C1 B2 B2 A3 A3 B3 C3 As you can see, the first complete kit becomes available in Shipment 2, The second complete kit in shipment 3, and the third complete kit also in shipment 3. Its pretty easy to work out in my head. But how do I do it with PHP/MYSQL?
  7. Hi. Can you post your login script? Your login script should create a $_SESSION variable. ie your admin username or something like that. Then at the top of every script that is admin only, you should check to see if this $_SESSION variable exists. If it doesn't, then redirect the user.
  8. Whoops! I've run into some trouble. I've changed the way I create the array and I can't seem to get it to work. I'm still getting my head around arrays and its still a bit confusing. I'm retrieving records from a database to create the array. Heres a snapshot of how the array is created. while($select=mysql_fetch_array($result)) { $arr[]=array($select['product'],$select['despatch_method']); } If the above solution can be modified to suit the way I create the array that would be great. Thank you!
  9. Hi, I've just recently discovered how useful writing my own php functions are. I've been using them mostly to tidy up repetitive code. However I want to know if this is possible. I have a mysql query which retrieves a customer's details from the database. I use it quite alot and want to place it inside a function. However I'm not sure how to return the values once the query is completed. I thought that the function might work similarly to an include, but this doesn't seem to be the case. Is a function the right way to go about this? $query="SELECT * FROM customers LEFT JOIN orders ON orders.customer_id=customers.customer_id LEFT JOIN contact ON contact.customer_id=customers.customer_id WHERE orders.order_id='$order_id'"; $result=mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if(mysql_num_rows($result)>0) { while($select=mysql_fetch_array($result)) { $first_names=$select['first_name']; $email=addslashes($select['email']); $invoice_location=$select['invoice_location']; } }
  10. Hi, I have a form that is dynamically generated. It pulls a number of items from the database and presents each one with a select menu next to it. The select menu presents a number of options that apply to each individual item. ie ITEM_47---<select>-- ITEM_56---<select>-- ITEM_32---<select>-- ITEM_63---<select>-- Now the problem I have is that if I use the ITEM_ID as the name of each field I wont be able to process the form because the process script won't know how to refer to the $_POST data in order to capture it. However if I give he fields generic names, then I won't be able to link each select menu with an ITEM_ID. It seems like a pretty basic task. I'm certain there is a solution. Please let me know if I need to clarify. Thanks.
  11. Hi I have a multidimensional array. The first key is the name of the product and the second is the delivery method. Stuff | Truck Widgets | Courier Thingies | Post Doovas | Truck I want to creats a list like so. Your Stuff and Doovas will be delivered by truck Your Widgets will be delivered by Courier Your Thingies will be delivered by Post Is there a way to sort the array into goups according to one of the keys? Thanks
  12. Hi, I need to process a dynamically generated form. Its a list of items with an item_id and an editable shipment_id in a text field. I've been giving each text input the name field[] so that I can process the form on another page using this code $shipment_id=$_POST['field']; $n=count($shipment_id); for($i=0;$i<$n;$i++) { Do something } Except now I realise I can't use the item_id for each field. Is there a way around this?
  13. Hi, I want to export my database without having to go into phpMyAdmin. ie. I want to run a script which will output the database to an SQL file. Is there a way to do this?
  14. Hi, I'm having a problem ordering my results by date on a datetime field. The result get ordered almost right, but not rightly enough. It seems to happen mostly where the results have a datetime a few seconds apart. Is this a mysql bug? Or is it the wrong approach? Or is there a way around it? Any help is appreciated. Here is the query if its of any help SELECT * FROM ( SELECT 'Order Created' AS event,invoice_date AS date_completed FROM orders WHERE order_id='$order_id' UNION ALL SELECT 'Customer added to system' AS event, customer_added AS date_completed FROM customers LEFT JOIN orders ON orders.customer_id=customers.customer_id WHERE order_id='$order_id' UNION ALL SELECT task AS event,task_added AS date_completed FROM tasks WHERE order_id='$order_id' UNION ALL SELECT CONCAT(amount,' received ',payment_method) AS event,payment_date AS date_completed FROM money_received LEFT JOIN payment_methods ON money_received.payment_method_id=payment_methods.payment_method_id WHERE order_id='$order_id' UNION ALL SELECT CONCAT(product,' added to order') AS event, item_added AS date_completed FROM items LEFT JOIN products ON items.product_id=products.product_id WHERE order_id='$order_id' UNION ALL SELECT CONCAT(product,' arrived in warehouse') AS event,arrival AS date_completed FROM items LEFT JOIN inventory ON items.inventory_id=inventory.inventory_id LEFT JOIN shipments ON inventory.shipment_id=shipments.shipment_id LEFT JOIN products ON items.product_id=products.product_id WHERE order_id='$order_id' AND arrival <='$today' ) AS a ORDER BY date_completed ASC";
  15. Here's the SQL to create the table if it helps. CREATE TABLE `tasks` ( `task_id` int(10) NOT NULL auto_increment, `task` varchar(1024) NOT NULL, `customer_id` int(10) default NULL, `order_id` int(10) default NULL, `assigned_to` int(2) NOT NULL, `assigned_by` int(2) NOT NULL, `task_added` datetime NOT NULL, `due_date` datetime NOT NULL, `completed_date` datetime default NULL, `task_type_id` int(2) NOT NULL, PRIMARY KEY (`task_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ; I'm not retrieving and displaying the value. Just took a peek in PHPmyadmin and saw that '0' was being inserted instead of NULL.
  16. No Luck again. It still inserts '0' instead of NULL even though the variable is set to NULL.
  17. Thanks, Except I should mention that the customer_id is not always NULL. Only in certain cases. Which means I need to assign NULL to the $customer_id variable rather than directly to the SQL. The methods you've both offered work, however what I really need to do is assign NULL to the variable. Any more ideas? Thanks
  18. Hi, SOmething strange seems to be happening when I try to run this query. I want to insert NULL as the customer_id, however the following query inserts '0' $customer_id=NULL; $query="INSERT INTO tasks (task_id,task,customer_id) VALUES ('','$task','$customer_id') The column has NULL set as the default. If I replace the variable $customer_id with NULL in my SQL it works fine. I'm not sure whats going on. Any clues?
  19. Hi, I'm writing a script which depending on certain factors includes the appropriate template. Rather than have each template as a seperate file I thought it would be easier to combine all the templates into a single file and then weed out the appropriate section to include using a switch statement. ie include("email_template.php?template=3); would include only what was found in case 3 of the switch statement. However, this doesn't seem to be working. I get the following error An error occurred in script 'C:\xampp\htdocs\mailroom.php' on line 145: include(email_template.php?template=3) [function.include]: failed to open stream: No error Is what I'm trying to do possible using this method? Can somebody suggest a different apporach? Thanks in advance.
  20. Hi, I need help with a join. This is what it looks like so far. SELECT * FROM users LEFT JOIN short_description ON users.business_id=short_description.business_id LEFT JOIN photosON short_description.business_id= photos.business_id LEFT JOIN location ON photos.business_id=location.business_id LEFT JOIN services ON location.business_id=services.business_id LEFT JOIN contact ON services.business_id=contact.business_id WHERE business_type=1 This query works perfectly fine. However, the table photos might not have have a record for that particular business id. ie, it is not compulsory to have a photo. When this occurs, no rows at all are returned for that business id. Is there another way of joining these tables to return the rest of the data when there is no photo record? Thanks.
  21. Hi, I was wondering iff there was a way to structure a query to create a set of nested lists. ie. I have a table with the columns NAME and CITY. I want to structure a query to retrieve records to create a list grouped by location that displays every name within that location. I tried the GROUP by clause, however that only returns one value for each location. SYDNEYName-one name-two [*]MELBOURNE name-three name-four name-five
×
×
  • 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.