How to insert multiple rows from a single query using eloquent/fluent

I have the following query: $query = UserSubject::where(‘user_id’, Auth::id())->select(‘subject_id’)->get(); and as expected I get the following result: [{“user_id”:8,”subject_id”:9},{“user_id”:8,”subject_id”:2}] Is there a way of copying the above result into another table so that my table looks like this? ID|user_id|subject_id 1 |8 |9 2 |8 |2 The problem I have is that the $query can expect any … Read more

Parse error: Syntax error, unexpected end of file in my PHP code

I got an error: Parse error: syntax error, unexpected end of file in the line With this code: <html> <?php function login() { // Login function code } if (login()) {?> <h2>Welcome Administrator</h2> <a href=\”upload.php\”>Upload Files</a> <br /> <a href=\”points.php\”>Edit Points Tally</a> <?php} else { echo “Incorrect login details. Please login”; } ?> Some more … Read more

How to output in CLI during execution of PHP Unit tests?

When running a PHPUnit test, I would like to be able to dump output so I can debug one or two things. I have tried the following (similar to the PHPUnit Manual example); class theTest extends PHPUnit_Framework_TestCase { /** * @outputBuffering disabled */ public function testOutput() { print_r(“Hello World”); print “Ping”; echo “Pong”; $out = … Read more

selecting unique values from a column

I have a MySQL table which contains the following type of information: Date product 2011-12-12 azd 2011-12-12 yxm 2011-12-10 sdx 2011-12-10 ssdd Here is an example of a script I use to get data from this table: <?php $con = mysql_connect(“localhost”,”username”,”password”); if (!$con) { die(‘Could not connect: ‘ . mysql_error()); } mysql_select_db(“db”, $con); $sql=mysql_query(“SELECT * … Read more

How to catch cURL errors in PHP

I am using PHP curl functions to post data to the web server from my local machine. My code is as follows: $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_POSTFIELDS, $data); $result = curl_exec($c); if (curl_exec($c) === false) { echo “ok”; } else { echo “error”; } curl_close($c); Unfortunately … Read more