Jump to content

mainstreetop

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Everything posted by mainstreetop

  1. I am relatively new to php and am working on a small project for myself where I need to make a secure https connection to my supplier's web server and have to pass a data string to the server using the POST method. I've googled 'using php to make https connections', but am having difficulty getting started in learning about this process. The PHP manual is somewhat too 'techie' for my level. Does anyone have a suggestion where I can get started? Thanks.
  2. I thought the additional key was necessary. If I were to create a single array using quantity => item# as the $k => $v, then the array will rearrange itself because of duplicate keys if the user enters the same quantity for two or more items. Or, maybe I do not fully understand which key is superfluous.
  3. Thank you HuggieBear. And, you are right... I'm sure there is a more efficient way. I did not realize I could simply use the '+' operator to achieve what I need. I'm going to work on simplifying the entire piece. Thanks again. I appreciate the help.
  4. I created it like that. The idea is to grab quantities and item numbers entered in an order form. So, I created an array of quantities and an array of item numbers. I then created array containing both sub-arrays. Now, I want to validate the item numbers against the database and insert the data into the 'cart' table. However, I'm trying to consolidate like items in the vent the user enters the same item number more than once. Hopefully, that made sense.
  5. @ huggiebear - Sorry about that and thanks for responding. This is somewhat new to me. Hopefully, this looks a little better. [0] Array => 0 ( [0] => 1 [1] => 12113 ) [1] => Array ( [0] => 2 [1] => 21200 ) [2] => Array ( [0] => 4 [1] => 10200 ) [3] => Array ( [0] => 1 [1] => yyyy ) [4] => Array ( [0] => 20 [1] => xxxxx ) [5] => Array ( [0] => 5 [1] => 21200 )
  6. I have the following multidimensional array where each sub-array represents quantity[0] and item #[1]: Array ( [0] => Array ( [0] => 1 [1] => 12113 ) [1] => Array ( [0] => 2 [1] => 21200 ) [2] => Array ( [0] => 4 [1] => 10200 ) [3] => Array ( [0] => 1 [1] => yyyy ) [4] => Array ( [0] => 20 [1] => xxxxx ) [5] => Array ( [0] => 5 [1] => 21200 ) I'm trying to consolidate like items. For example I need to create a new array that reflects any duplicate part numbers with a combined quantity. (ie. ... [0] => 7 [1] => 21200 ...
  7. I'm an idiot... switched the backslashes in the path to forward slashes. Problem solved!
  8. As an edit to my original post, I noticed (when viewing the html page source) the following: <p><img src='http:\www.oppictures.com\SINGLEIMAGES@$x[0]' </p> I'm not sure why the @ symbol is being rendered. Any ideas?
  9. I have an array ($other_images) that contains image file names separated by semi colons. I can successfully echo the individual values using echo $other_images[0], $other_images[1], $other_images[2]... When I put it in a for loop, though, I run into the followng error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in... Here is my code: <?php $other_images = explode(";", $data['ItemAltImage']); for($i=0; $i<count($other_images); $i++) { echo "<p><img src='http:\\www.oppictures.com\SINGLEIMAGES\100\" . $other_images[$i] . "' /></p>"; } ?> This is the result of print_r($other_images): Array ( [0] => UNV21200_3_2.JPG [1] => UNV21200_2_2.JPG [2] => UNV21200_4_1.JPG [3] => UNV21200_8_1.JPG [4] => UNV21200_5_1.JPG [5] => UNV21200_6_1.JPG [6] => UNV21200_7_1.JPG [7] => UNV21200_9_1.JPG ) Do you see where I'm making a mistake? Thanks
  10. Barand - You're right... this does seem overly-complicated. I guess this all started because I need three pieces of data... id, category and count. I need the category id because it is the only unique field. Category can appear more than once in the DB. I used the array approach to group the id's and get a count. It seemed running another mysql query was too taxing. Plus, being new to PHP, I felt this would help understand arrays a little better. I imagine this does not paint a full picture without seeing the code, but I wanted to give some insight as to why I traveled down this path. Mike
  11. KHR2003 - Thank you for responding. I am trying to sort the array all the way down. I wound up rearranging the array as below and then using ksort(). However, I'm sure this is not the most efficient way to accomplish the task. foreach($levels as $category => $value) { foreach($value as $id => $count) { $new[$level] = array($key => $count); } } ksort($new);
  12. Someone from this forum recently helped me with structuring an array. It outputs as... Array ( [525] => Array ( [binders] => 992 ) [372] => Array ( [Corporate Kits] => 105 ) [521] => Array ( [binder Pockets] => 10 ) [431] => Array ( [Desktop Supplies Organizers] => 2 ) [522] => Array ( [binder Posts] => 3 ) ) [brand_id] => Array ( [category] => item_count ) How would I sort the array by category and preserve the keys? I've tried array_multisort(), but can't seem to figure out how to refer to the ['category'] key. Thanks Mike
  13. @kenrbnsn... I am using your code to get the brand, id and count. I found that your example was easier for me to sort the brands using ksort() to get the brands to appear alphabetically. Actuaally, you code was simply easier all around. Would you, by chance, know how to sort the keys in a specific order? I've looked into uksort(), but the order I'd like to see is two specific brands (if they exist) and then alphabetically for the remaining brands. In my previous example, I'd like to see Malibu and Chevy as always the number 1 & 2 brand respectively (again, if they exist). The remaining brands can simply sorted by alpha. If you have any thoughts... Thanks. Mike
  14. @kenrbnsn Thank you for taking the time to reply. I am going to test your code. I am pretty new to php so it takes me a while to walk through the steps and understand. I had been making making attempts to solve the problem. I came up with what's below. However, your code seems more simplified. $a = array("malibu","impala","escort","camaro","impala","venture","impala", "venture"); $b = array("100","101","102","103","101","104","101", "104"); $a1 = array_count_values($a); $a2 = array_unique($a); $a3 = array_unique($b); $count = array_values($a1); $brand = array_values($a2); $brandId = array_values($a3); for($x=0; $x<count($brand); $x++) { echo "<p>" .$brand[$x]. " - " .$brandId[$x]. " - " .$count[$x]. "<br/>"; } Thanks again. Mike
  15. I have two arrays... One is brand($a) and the other is brandId($b): $a = array("malibu","impala","escort","camaro","impala","venture","impala", "venture"); $b = array("100","101","102","103","101","104","101", "104"); I want to echo the unique occurrence of brand & brandId along the count within each brand. Something similar to: brand - brandId - count malibu - 100 - 1 impala - 101 - 3 escort -102 - 1 camarao - 103 - 1 venture - 104 - 2 I guess I want a multi-dimensional array containing brand, brandId and count. I see array_count_values may help, but having trouble seeing it all the way through. Thanks.
  16. I am having a difficult time figuring out how to retrieve the information I need. I have an ORDERS table that contains an orderId, userId, productNumber, quantity and price for that orderId. I am JOINING other tables to get the company/user/shipping info. I'm trying to create a table that displays the items within each orderId. So, I figured arrays would be the best way to store the data. One for the order header information (static info) and one for the order details (different items in each order). I understand how to create each array. I'm just not sure how to arrange the arrays to output to a table. I'm guessing it's a FOR LOOP within a FOR LOOP, but can't quite get the login. Here's my code so far... // create order header array // the GROUP BY is intended to give me the unique orderId $q = mysql_query(" SELECT orders.*, ship.*, company.*, user.* FROM orders JOIN company ON orders.companyId = company.companyId JOIN ship ON orders.shipId = ship.shipId JOIN user ON orders.userId = user.userId GROUP BY orderId ") or die (mysql_error()); while($row = mysql_fetch_array($q)) { foreach($row as $key => $value) { if(is_string($key)) $orderHeader[$key][] = $value; } } // and the orderDetails array // the item table gives me product description information // this array may, for example, contain one or two items per order $q = mysql_query(" SELECT orders.*, item.* FROM orders JOIN item ON orders.productNumber = item.ProductNumber ") or die(mysql_error()); while($row = mysql_fetch_array($q)) { foreach($row as $key => $value) { if(is_string($key)) $orderDetails[$key][] = $value; } } Any thoughts on how to get the items within each orderId grouped together for display? Thank you. Mike
  17. No - I showed all the code. I understand what you are saying. I'm going to remove it. Thanks again for your help. I was stuck on this for quite some time.
  18. @PFMaBiSmAd... Thank you for the link. I changed the $_POST['submit'] to $_POST['submit_x'] and the mysql query worked as hoped in IE8. I also noticed that removing the $php_self from the action='...' attribute does perform the same except that it leaves the '#' symbol in the url after clicking the image. Using the $php_self keeps the url clean. I know this may be a trivial matter, but does the '#' symbol in the url cause any other issues? @ l0ve2hat3... Thank you for your reply, too. I am going to use the first suggestion. I'm very new to all of this and it may be a little while before I become comfortable with JS.
  19. Trying to call php function that execute's a mysql command via input type=image. I want the user to be able to click the image which adds an item to his 'My List' while remaining on the same page. This works in Chrome, but not in IE8. Does anyone have any ideas? I'm trying to avoid using $_GET. This is my test.php file: <?php if (isset($_POST['submit'])) { include('includes/dbconnect.php'); mysql_query ("INSERT INTO mylist VALUES ('','1','12345','')"); // redirect to avoid refresh adding duplicate entries header('Location: test.php'); } ?> <html> <body> <form action="<?php $php_self ?>" method="post"> <input type="image" name="submit" value="submit" src="images/mylist.jpg" /> </form> </body> </html>
  20. I posted this previously and did receive some suggestions, but I am still unclear how to achieve what I need. Here is my query... $sql = 'SELECT item.*, attributes.* FROM item LEFT JOIN attributes ON item.ProductNumber = attributes.ProductNumber WHERE item.ProductNumber = 9503731 ORDER BY attributes.AttributePriority'; $result = mysql_query($sql); while ($row = mysql_fetch_array($results)) { $ProductNumber = $row['ProductNumber']; $Image = $row['ItemImage']; $AttribPriority = $row['AttributePriority']; $AttribName = $row['AttributeName']; $AttribValue = row['AttributeValue']; } Below is the information I am having trouble rendering properly. It is my ATTRIBUTES table. Every product in the ITEMS table has the potential for up to 20 attributes where I would like to display both the AttributeName & AttributeValue. I am trying to echo each attrib name & value. This is how the data is stored in the 'attribute' table: ProductNumber AttributePriority AttributeName AttributeValue 9503731 4 Clerk Totalizers [Nom] 4 9503731 5 Compartments 4 Bill Drawer 9503731 5 Compartments 5 Coin Drawer It was previously suggested that I set up my code like this: $getAll_array = array(); while ($row = mysql_fetch_array($results)) { array_push($getAll_array, $row); } If I print_r($getAll); I see all the data within the array. I'm just not sure how to retrieve the rows individually so I can place the variable in HTML for display. Thanks for any help.
  21. @ GOAT... Thank you for responding. I am sorry, but I am very new to all of this. I do not fully understand how I would echo out each of the attributes. Also, I did not include the full contents of my WHILE statement (not sure if it makes a difference), but I am pulling fields from other tables, too. I only showed the $row[''] 's pertaining to the attributes. Does your suggestion then apply for everything with the WHILE statement? Hopefully, that made sense.
  22. I think I need to set up an associative array... Here's my query: $sql = 'SELECT item.*, attributes.* FROM item LEFT JOIN attributes ON item.ProductNumber = attributes.ProductNumber WHERE item.ProductNumber = 9503731'; $result = mysql_query($sql); while ($row = mysql_fetch_array($results)) { $ProductNumber = $row['ProductNumber']; $AttribPriority = $row['AttributePriority']; $AttribName = $row['AttributeName']; $AttribValue = row['AttributeValue']; $Att_array = array($AttPriority, $AttName, $AttValue); } This is how the data is stored in the 'attribute' table: ProductNumber AttributePriority AttributeName AttributeValue 9503731 4 Clerk Totalizers [Nom] 4 9503731 5 Compartments 4 Bill Drawer 9503731 5 Compartments 5 Coin Drawer I can not figure out how to store these multiple attributes so I can render them on the web page. I tried setting up a foreach to display the contents of the array: foreach ($Att_array as $AttValues) { echo $AttValues; // this is where I get lost... } I need to be able to display EACH AttributePriority, AttributeName & AttributeValue. I know I'm missing something... just not sure what it is. Thanks for any help.
  23. @harristweed... Never mind previous issue. I echoed the $path with the <br> and noticed the output as: 1.jpg 2.jpg 3.jpg There is a space between each filename. So, I changed the explode() to reflect the delimiter as a semi-colon followed by a space: $jpg_array = explode(", ", $row['Image']); Amazing how one simple character can cause so much frustration. I imagine, though, as I move along, I'll learn how to efficiently debug???
  24. @ harristweed... Not sure if you're still monitoring this thread, but I am noticing one small problem that I can't seem to figure. My mySql field contains this data which is separated by semi-colons: 1.JPG; 2.JPG; 3.JPG I'm exploding this file using (as you helped previously): $jpg_array = explode(';',$row['Images']); // THIS WORKS WELL Trying to display each image by: foreach ($jpg_array as $key => $path) { echo "<img src='http://www.website.com/images/" . $path . "' />"; } If I echo $path . "<br/>": I get: 1.jpg 2.jpg 3.jpg Everything seems to be as expected if mySql field contains one image. However, when there are multiple images, there is a problem. When I echo the image with that foreach loop, only the first image is being displayed. The other two are not. Those 'invalid path' (sorry, I'm sure of their proper name) boxes are being rendered in the browser. Do you see what I'm missing?
×
×
  • 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.