How to show sql columns (not rows) randamly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to show sql columns (not rows) randamly

I have a SQL record which is as I'd, que, ans1, ans2, ans3, ans4. now I want to show answers randomly how to do it using PHP? also show me that how I can echo them in HTML5

30th Jan 2018, 8:33 AM
Harish Suthar
Harish Suthar - avatar
6 Answers
+ 3
$connectionInfo = array("Database"=>"dbname"[, "UID"=>"username", "PWD"=>"password"]) $serverName = "serverName\instanceName" // add ", portnumber" if you want $conn = sqlsrv_connect( $serverName, $connectionInfo) $randCol = array_rand(array("ID", ....), 1) $table = "tableName" echo(sqlsrv_query( $conn, "select ? from ?;", array($randCol, $table))
31st Jan 2018, 12:08 PM
Rugved Modak
Rugved Modak - avatar
+ 3
check the connection with if($conn){sqlsrv_query()} else{print_r(sqlsrv_errors(), true)}
31st Jan 2018, 12:11 PM
Rugved Modak
Rugved Modak - avatar
+ 3
sorry I'm not a php coder so I missed the ; everywhere
31st Jan 2018, 12:12 PM
Rugved Modak
Rugved Modak - avatar
+ 1
actually I'm mechanical engineer but coding is my passion so I'm gone build website for engineering for exams and general questions that help people, this problem I solved yesterday but now I have another problem that I mentioned in my other que. if u able to solve it, help me.
31st Jan 2018, 12:15 PM
Harish Suthar
Harish Suthar - avatar
+ 1
btw thanks for trying@modak,
31st Jan 2018, 12:17 PM
Harish Suthar
Harish Suthar - avatar
+ 1
How to change bg color of list if its value is xyz onclick I have 5 variables $xyz ,$a ,$b, $c, $d. and echo $a , $b, $c, $d for Selection . now one of them is = $xyz . so how to change bgcolor of that variable on selection if selected variable is = $xyz. also so how to implement it in HTML below is the link of my code https://code.sololearn.com/w9wf4viYsLhT/#php
31st Jan 2018, 12:18 PM
Harish Suthar
Harish Suthar - avatar