0

When i use random function it is working it give me 3 random value , but when i use the variable who contain a number , the number stay the same ?

foreach ($list_of_codes as $k => $v)
{
    //  $rand = rand(1,15);
    $rand = $refidorder;
    $code = $rand++;
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
Jhonyy
  • 11
  • 6
  • $rand++ is a post increment, so the value is used and then incremented. Use ++$rand. – Nigel Ren Nov 16 '17 at 17:49
  • `$rand = $refidorder;` So what's `$refidorder`, and where is it changed inside your loop? If it isn't changed, then it will always have the same value that's being assigned to `$rand`, and to `$code` – Mark Baker Nov 16 '17 at 17:49
  • You should use `$rand + 1`. It makes no sense to increment the variable if you're just going to reassign it the next time through the loop. – Barmar Nov 16 '17 at 17:50
  • still not working its give me the same value – Jhonyy Nov 16 '17 at 17:50
  • You need to clarify the question then. Show what you're expecting and what you're getting instead. – Barmar Nov 16 '17 at 17:51
  • The code you've posted will always give the same value in $rand and in $code; there's nothing to change it.... what is $refidorder? – Mark Baker Nov 16 '17 at 17:54
  • $sql = 'SELECT id_order_detail FROM '._DB_PREFIX_.'order_detail WHERE id_order = '.$params['id_order'].' AND product_id = '.$idproductoforder.''; $refidorder = Db::getInstance()->getValue($sql); – Jhonyy Nov 16 '17 at 17:56
  • this query return one id at time , i want to make a query for each id but cant make it , – Jhonyy Nov 16 '17 at 17:59

0 Answers0