PHP query result into variable

Hi everyone I am a beginner programmer trying to get query results into variable in PHP. For registeration purposes, I want to assign an available campaignID to variable $campaignID, so I can insert $campaignID along with other variables to the new user row. I only need help on getting my result of my SELECT Statement into the variable campaignID! I am aware that there are multiple questions asking the exact thing want like 1 & 2. However, I have been trying the solutions for hours now but to no avail and I need help to apply the answers to my situation.