How Bitcoin mining contributes to confirmations? Based on my knowledge I know (maybe wrong) when a miner is doing hash, he is inputting any arbitrary values, in order to get a value that can be hashed into something with certain preceding zeros. When he got that value, he put that value into the blockchain and generate a new block.

Then how is this contributing, or say, relating to the confirmations? Since the miners are just guessing arbitrary values to get the 0000000 preceded hash.

I think I must have some misunderstanding. I want to know how the hash-guessing is related to confirming the transactions.
he is inputting any arbitrary values, in order to get a value that can be hashed into something with certain preceding zeros. When he got that value, he put that value into the blockchain and generate a new block.


It happens in reverse.
First the miner builds the new block itself. Then builds its header, then hashes that header. Also what the miner looks for is not preceding zeros, but instead is a number (hash result interpreted as integer) that is smaller than the target.  

The steps are something like this:


Take 0 to max (to fill the block) number of transaction from mempool
Build the mandatory coinbase transaction
Build the hashMerkleRoot based on 1&amp;2
Fill the block header fields: Version, hashPrevBlock and Bits are unchanging; hashMerkleRoot, Time and Nonce can change
Start a loop and change the variables on its iterations and hash the header.
Convert the result of the hash to an integer and compare it with the target.
Break out of the look and publish the result if hash &lt;= target or if someone else were luckier and found and published the same block.


You can find more information in these links:
https://en.bitcoin.it/wiki/Block_hashing_algorithm
https://en.bitcoin.it/wiki/Proof_of_work


  Then how is this contributing, or say, relating to the confirmations?


Confirmation is when a transaction is included in a block that was found. 1 confirmation means the transaction is inside the last found block, any subsequent number shows the depth of the transaction compared to the block height of that time and is an indication of how hard it would be to perform a double spend.  https://en.bitcoin.it/wiki/Confirmation