Jump to content

InfinityRogue

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

InfinityRogue's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. it's still doing it wrong. When i'm creating $productArray i would get a value like: $productArray[0] = "1"; (where 1 is the productnumber or productsku) and for $selectArray i would have: $selectArray[1] = "1"; (where 1 is the productsku of the product and 1 is the selectedproductsku) I think it might go wrong in the foreach loop where it says isset($selectArray[$valueArray]. It's somehow not comparing it right. Maybe i'm not understanding this whole multidimensional array stuff.
  2. i found out that i wasnt creating any arrays from what i got from the database so now i changed it to this but somehow for p={1,2,3,4,5} and s={1,2,4} for example it keeps writing out 1, 3 times. [code] $query  = "SELECT productsku,price FROM dprices WHERE companyname='$companyname'"; $result = mysql_query ($query);             while ($query_data = @mysql_fetch_array ($result)) { $productsku = $query_data['productsku']; $price      = $query_data['price'];             if($price != 0) { $productArray[] = $productsku;             $querytemp  = "SELECT productsku FROM temporder WHERE companyname='$companyname'"; $resulttemp = mysql_query ($querytemp); while ($query_temp = @mysql_fetch_array ($resulttemp)) { $selectproductsku = $query_temp['productsku'];         $selectArray[$productsku] = $selectproductsku; //print $selectArray['productsku']; } } }             foreach($productArray as $index => $valueArray) { if ( isset($selectArray[$valueArray])) { // then do something because it is found echo $selectArray[$valueArray]; } else { // use the product values echo "select"; } } [/code]
  3. grrr it's not doing it. I think the problem is in the arrays. The first array which selects from dprices, i should probably just get productsku and price. From the second array i should probably just get productsku and quantity. So im trying to compare the two productskus. Problem is that now it is comparing them but just writing out the one that they dont have in common... twice. i have p={1,2,3,4,5} and s={1,2,4} (numbers being the productskus from each table in the database) i think the problem is that i cant get to the productsku and price in one, and productsku and quantity in the other. (price and quantity will be used later for beauty purposes).
  4. I realize that some of the things like $price = $query_data["price"]; has not been updated to the new array name, but this is where i don't know what to change.
  5. perhaps i should paste everything i have right now cause i'm not sure i'm getting the right items. [code] $query  = "SELECT * FROM dprices WHERE companyname='$companyname'"; $result = mysql_query ($query); //$query_data = @mysql_fetch_array ($result); while($newresult[$i++]=mysql_fetch_array($result));             $querytemporder    = "SELECT * FROM temporder WHERE companyname = '$companyname'"; $resulttemporder  = mysql_query ($querytemporder); //$query_temporder = @mysql_fetch_array ($resulttemporder); while($newresulttemporder[$i++]=mysql_fetch_array($resulttemporder)); do {     if(in_array(current($newresulttemporder),$newresult))     {           $price = $query_data["price"];   if($price != 0)   { $orderproduct  = $query_temporder["productsku"]; $orderquantity = $query_temporder["value"]; $queryprod    = "SELECT * FROM products WHERE productsku='$orderproduct'"; $resultprod    = mysql_query($queryprod); $query_prod    = @mysql_fetch_array($resultprod); $frequency    = $query_prod["frequency"]; $description  = $query_prod["description"]; $color        = $query_prod["color"]; echo "<tr>\n"; echo "<td width=\"110\" height=\"20\" align=\"center\">$orderproduct</td>\n"; echo "<td width=\"80\" height=\"20\" align=\"center\">$frequency</td>\n"; echo "<td width=\"210\" height=\"20\" align=\"center\">$description</td>\n"; echo "<td width=\"80\" height=\"20\" align=\"center\">$color</td>\n"; echo "<td width=\"110\" height=\"20\" align=\"center\">                 <select name=\"prod_$orderproduct\">                 <option value=\"$orderquantity\">$orderquantity</option>                 <option value=\"select\">SELECT</option>"; for($i=1; $i <= 50; $i++) { $quantity = $query_prod["quantity$i"]; if (($quantity != 0) && ($quantity != $orderquantity)) { echo "<option value=\"$quantity\">$quantity</option>"; } } echo "</select></td>\n"; echo "<td width=\"110\" height=\"20\" align=\"center\">$price</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td colspan=\"6\" height=\"20\">                 <hr size=\"2\" width=\"680\" color=\"black\" align=\"center\"></td>\n"; echo "</tr>\n"; }     }     else     { $price        = $query_data["price"];         if($price != 0) { $productsku    = $query_data["productsku"];     $orderquantity = $query_temporder["value"]; $queryprod  = "SELECT * FROM products WHERE productsku='$productsku'"; $resultprod  = mysql_query($queryprod); $query_prod  = @mysql_fetch_array($resultprod); $frequency  = $query_prod["frequency"]; $description = $query_prod["description"]; $color      = $query_prod["color"]; echo "<tr>\n"; echo "<td width=\"110\" height=\"20\" align=\"center\">$productsku</td>\n"; echo "<td width=\"80\" height=\"20\" align=\"center\">$frequency</td>\n"; echo "<td width=\"210\" height=\"20\" align=\"center\">$description</td>\n"; echo "<td width=\"80\" height=\"20\" align=\"center\">$color</td>\n"; echo "<td width=\"110\" height=\"20\" align=\"center\">                 <select name=\"prod_$productsku\">                 <option value=\"select\">SELECT</option>"; for($i=1; $i <= 50; $i++) { $quantity = $query_prod["quantity$i"]; if ($quantity != 0) { echo "<option value=\"$quantity\">$quantity</option>"; } } echo "</select></td>\n"; echo "<td width=\"110\" height=\"20\" align=\"center\">$price</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td colspan=\"6\" height=\"20\">                 <hr size=\"2\" width=\"680\" color=\"black\" align=\"center\"></td>\n"; echo "</tr>\n"; }     } } while(next($newresulttemporder)); [/code] Sorry for the mess, but like i said i'm new to this hehe. Even if i added the line that you gave me last, i'm no longer sure how i would get the individual elements from the row in the database now. As you can see the only difference in how it is written out in html is what is shown in <select>
  6. No, i'm getting my elements from a database, so i'm calling the database first for both arrays. But as they come in it's getting it from mysql_fetch_array which i believe only takes in one row at a time. Is there a way that i can get all the rows from the database and create an array from that? Sorry, a bit new at this.
  7. Sorry, i guess i was wrong about having two arrays. Apparently i only have 2 rows at a time. [code] $query  = "SELECT * FROM dprices WHERE companyname='$companyname'"; $result = mysql_query ($query);             $query_data = @mysql_fetch_array ($result);       $querytemporder    = "SELECT * FROM temporder WHERE companyname = '$companyname'"; $resulttemporder  = mysql_query ($querytemporder); $query_temporder = @mysql_fetch_array ($resulttemporder); [/code] So when i tried your suggestion, nothing was written. I'm guessing since i can only compare 2 items at a time. Any suggestions as to how i can do it then?
  8. Hi, I have a situation where i have a customer that first selects which products he wants and then it stores it in a database. He can then choose to edit his order and i would like to display what he has already selected previously instead of him having to redo the entire order. So, i now have these two arrays: one which is the list of products, and one that is the selection he has already made. To make the example easy, lets say that i have an array for products called p={1,2,3,4,5} where the numbers are the products. Then i have an array for the selection called s={1,2,4}. Anything that the two arrays have in common will be displayed as a number, while the remaining products just are displayed with the text SELECT in the dropdown box i have in html. I dont have a problem writing the stuff out in Html. I have a problem comparing the two arrays and getting the right result. The end result should be: 1 2 SELECT 4 SELECT I have this so far: [code] $query  = "SELECT * FROM dprices WHERE companyname='$companyname'";  //Get the list of products $result = mysql_query ($query); while ($query_data = @mysql_fetch_array ($result)) {     $productsku  = $query_data["productsku"];  //Here i take the first product in the productlist     $querytemporder    = "SELECT * FROM temporder WHERE companyname = '$companyname'";     $resulttemporder  = mysql_query ($querytemporder);    //Get the selected products     while ($query_temporder = @mysql_fetch_array ($resulttemporder))     {             $orderproduct  = $query_temporder['productsku'];  //Here i get the selected products to                                                                                   compare to the productlist     if($orderproduct == $productsku)             {                 ......  //Here is what it writes out in html ... [/code] How can i do this? (Let me know if i haven't explained it well enough) I appreciate any help i can get.
×
×
  • 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.