Jump to content

AikenDrum

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

AikenDrum's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi there, many thanks indeed for the speedy reply - it's almpst there but not quite right. When I use combine, it uses the first array as the key, and does not allow for a 3rd or 4th array to be added. This is what it returns: This is the code I used: $nameUnemPost = (isset($_POST['nameUnem']))? $_POST['nameUnem'] : ""; $commentUnemPost = (isset($_POST['commentUnem']))? $_POST['commentUnem'] : ""; $combined = array_combine($nameUnemPost, $commentUnemPost); Any ideas as to the next step? Many thanks indeed AikenD
  2. Hi there, I am using HTML forms to post values from a data entry page. When they arrive on the second page - I have to extract them from the POST array. This is fine, but I now have to merge them somehow. When I use print_r to view the POSTed data, I see: [namesUnem] => Array ( [0] => Brian [1] => Richard [2] => Sarah ) [commentsUnem] => Array ( [0] => Brian Comments here [1] => Richard Comments should be entered here [2] => Sarah's Comments were also entered here ) [namesHW] => Array ( [0] => Sally [1] => Kate [2] => William ) [commentsHW] => Array ( [0] => Sally Comments here [1] => Kate's Comments should be entered here [2] => William's' Comments were also entered here ) There are 2 more such arrays being POSTed. I would need to merge in order to see the following: Any help greatly appreciated Kindest Regards AikenD
  3. Hi again, I updated it and this does what I want : $i = 0; $countLI = count($postID); while ($i < $countLI) { $qryLi = "INSERT INTO qLi(qid, prodID, Qty) VALUES('$qid', '$postID[$i]','$postQty[$i]') "; $resultLi = @mysql_query($qryLi); if( ! $resultLi ) { die( "Could not execute query '$qryLi'. (Reason: " . mysql_error() . "). " ); } $liid = mysql_insert_id(); // echo $liid; $qryLi2 = "Update qLi p, onlineprods pp SET p.Cost = pp.Cost, p.Product = pp.Product, p.ImgName = pp.ImgName WHERE p.prodID = pp.id AND p.id = '$liid'"; // echo $qryLi2; $resultLi2 = @mysql_query($qryLi2); if( ! $resultLi ) { die( "Could not execute query '$qryLi'. (Reason: " . mysql_error() . "). " ); } echo "<br>".$qryLi; $i++; } quite chuffed actually that it works - probably not optimal but it works Cheers AikenD
  4. Actually - I used the following and it works - if anyone can see what may be wrong with it - please let me know $i = 0; $countLI = count($postID); while ($i < $countLI) { $qryLi = "INSERT INTO qLi(qid, prodID, Qty) VALUES('$qid', '$postID[$i]','$postQty[$i]') "; $resultLi = @mysql_query($qryLi); if( ! $resultLi ) { die( "Could not execute query '$qryLi'. (Reason: " . mysql_error() . "). " ); } $qryLi2 = "Update qLi p, onlineprods pp SET p.Cost = pp.Cost WHERE p.prodID = pp.id"; $resultLi2 = @mysql_query($qryLi2); if( ! $resultLi ) { die( "Could not execute query '$qryLi'. (Reason: " . mysql_error() . "). " ); } echo "<br>".$qryLi; $i++; }
  5. Hi there, I have two table - Products and LineItems. I insert 3 values into LineItems - the quoteID, productID and Quantity - I then need to have the Cost field and imageName field in the LineItems table populated from the Products table where the productID in the newly created row in LineItems matches the productID form the Product table. Here is my current code: $i = 0; $countLI = count($postID); while ($i < $countLI) { $qryLi = "INSERT INTO qLi(qid, prodID, Qty) VALUES('$qid', '$postID[$i]', '$postQty[$i]')"; $resultLi = @mysql_query($qryLi); if( ! $resultLi ) { die( "Could not execute query '$qryLi'. (Reason: " . mysql_error() . "). " ); } $i++; } id someone could help me here, I would be so thankful - it's 5:20 in the morning here, been up all night and only now realized what I need.
  6. Hi there, when I use it together with array_intersect_key it works - many thanks I really need to go to bed before silly hour ! Thank you
  7. Hi there, I have 3 POSTed arrays - each with the same amount of elements, but in some elements the values will be missing. I am trying to remove related items from the arrays where $postQty has no value in it. In other words - in each array, the element is only valid where there is a value in $postQty in the corresponding index Example array after POSTing: $postID = [O] => 2 [1] => 4 [2] => 7 $postQty = [O] => 20 [1] => [2] => 5 $postQtyGot = [O] => 7 [1] => [2] => In $postQty above, the second element [1] has no value. I need the corresponding (by index) elements removed in all the arrays - so if in $postQty, element [1] has no value, then element [1] should be removed from all 3 arrays - as below $postID = [O] => 2 [1] => 7 $postQty = [O] => 20 [1] => 5 $postQtyGot = [O] => 7 [1] =>" The elements have been removed from the arrays where the index corresponds to the element index in $postQty where there was no value. Here is my code so far : $countID = count($postID); // how many have been posted $x=0; // counter echo $countID; // test while ($x < $countID) { if( $postQty[$x]==''){ unset($postID[$x]); unset($postQty[$x]); unset($postQtyGot[$x]); continue; } $x++; } echo '<pre>'; print_r($postID); print_r($postQty); print_r($postQtyGot); echo '</pre>'; exit(); It takes ages to run, then only echos the $countID, nothing is retunred from print_r Anyone able to see what I am doing wrong ? much Appreciated, really, in advance, AikenD
  8. Hi there - sorry - I spoke to soon. I have found what I think is a bug: Example 1: Qty = 24 Array ( [16] => 1 [8] => 1 ) CORRECT Example 2: Qty = 25 Array ( [16] => 2 ) WRONG I would expect to see ( [16] => 1 [8] => 1 [4] =>1 ) Excuse me if I was not clear enough - Minimum ports for 25 cameras = 1*16 + 1*8 + 1*4 Perhaps you can see whay is wrong ? Thank you very much AikenD
  9. Hey Kathas - that's it ! MANY thanks - works a treat Kindest Regards AikenD
  10. Hi there, I am looking for help with the following : I have cameras. I have dvr's - 3 types - 4 channel, 8 channel, and 16 channel. Someone on the web page enters the amount of cameras - I need to work out how many dvr's (dependent on channels) they need My code so far is pretty poor - if($qty % 4 >= 0){ $dvr = 4; } if ($qty > 4 && $qty < 9) { $dvr = 8; } if ($qty > 8 && $qty < 17) { $dvr = 16; } if ($qty > 16) { $mod = $qty % 4; echo "mod = ". $mod."<br><br>"; } echo "You need a ".$dvr. " port dvr"; Example - if $qty=19; It should read "1 * 16 port dvr and 1 * 4 port dvr" Example - if $qty=24; It should read "1 * 16 port dvr and 1 * 8 port dvr" Example - if $qty=30; It should read "2 * 16 port dvr" I tried mucking around with the mod function - and probably need some sort of recursion - but am a bit lost now. Any help greatly appreciated kindest Regards AIken D
  11. So, that works - great - something else learned I have echo many values, but this is great - Many thanks indeed, kindest Regards AikenD
  12. Hi there, many thanks for the speedy reply - when you say "indexed by the common value for each (i'm guessing ID, but this could be date?) and calling from each " - do you mean "using a value that each array has in common" ? They share an ID - it is not the row ID , but another ID ( seen as $agNr = $row['AG_nr']; ) Would I be able to use this ? As in : while ($row = mysql_fetch_array($resultArea)) { // Add row to array by using unique value, shared by both result sets, as the index $resultsThisMonth[$row['agNr']] = $row; } If so, it seems relatively simple :-)
  13. Hi there, I am trying to do the following, but getting confused along the way (php / mysql newbie): I have 2 queries - one from this month and one from last month. I need to show last months values as a tool tip (or perhaps as a second row) for this month (in order to be able to compare the values) Here is my current code - I am aware where the mistake is - but no idea how to fix it (i think th emistake is that there is no relationship between the 2 queries): query for this month: $qryArea = "SELECT * FROM payments WHERE area='$area' AND month='$month' ORDER BY ag_nr"; $resultArea = mysql_query( $qryArea ); query for last month: $qryAreaLast = "SELECT * FROM payments WHERE area='$area' AND month='$previous' ORDER BY ag_nr"; $resultAreaLast = mysql_query( $qryAreaLast ); data extraction from q this month: while($row = mysql_fetch_array($resultArea)) { $agNr = $row['AG_nr']; $id = (isset($row['id']))? $row['id'] : ""; $Size = (isset($row['Size']))? $row['Size'] : ""; } data extraction from q last month: while($rowLast = mysql_fetch_array($resultAreaLast)) { $agNrLast = $rowLast['AG_nr']; $idLast = (isset($rowLast['id']))? $rowLast['id'] : ""; $SizeLast = (isset($rowLast['Size']))? $rowLast['Size'] : ""; ?> // and lastly - here is the part where I TRY to do what I need: <input type="text" name="Size" id="<?php echo 'Size'.$id; ?>" title="<?php echo $SizeLast ?>" value="<?php echo $Size ?>" /> <?php } ?> </code> At the moment, the $SizeLast is the simply repeated for each of the $Size - in other words, it is exactly the same on each $Size - I think I need to say something like -> title=" $SizeLast where $agNrLast = agNr " but am unsure where to do this - in the mysql query (by having one query run, then somehow separating the months) or in the php There are more than just one column I want to do this on - it's not just the Size column. Any help greatly appreciated Kindest AikenD
  14. Bingo - many thanks indeed - I had my own version worked out - but this is better - AikenD
  15. Hi there, I am still getting no response back - not even a zero now :-( I again tried replacing 7 with 8 (I think that's correct) $out just comes back empty
×
×
  • 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.