thatguywhoasksquestions Posted January 19, 2014 Share Posted January 19, 2014 The purpose of the MySQL query is to go through each row in the highscores table, and for each row, it increments @pos by each row number. For example: @pos = row 1, @pos = row 2. That is the subquery. The main SELECT will then go through all the returned rows, find the row with the userid of the user in question, and return that rows position. It works perfectly fine when ran in phpMyAdmin, e.g: http://puu.sh/6q5Gx.png The query was ran on the user who is #1 on the highscores, and as you can see, returned his appropriate rank; however, in my PHP function, I don't seem to be getting any results. public function getRank($id){ $query = $this->db->processQuery(" SET @pos=0; SELECT pos FROM ( SELECT h.`userid`,@pos:=(@pos+1) AS pos FROM `highscores` AS h ORDER BY `money_earned` DESC ) as x WHERE x.`userid` = ? ", array($id), true); return $query[0]['pos']; } I even print_r()'ed the $query variable, and I got nothing but an empty array. If this helps, here's processQuery: /* * @METHOD processInsertQuery * @DESC prepares a query for use, then runs it */ public function processQuery($query, array $binds, $fetch = false) { $query_handle = $this->dbc->prepare($query); if(!$query_handle->execute($binds)){ $error = $query_handle->errorInfo(); echo $error[2]; } //update insertId var $this->insertId = $this->dbc->lastInsertId(); //incase we ever want to get the number of rows affected //we set our row_count variable to the number of rows affected $this->row_count = $query_handle->rowCount(); if($fetch == true) return $query_handle->fetchAll(); } Link to comment https://forums.phpfreaks.com/topic/285482-running-query-in-phpmyadmin-gets-results-however-not-in-php/ Share on other sites More sharing options...
thatguywhoasksquestions Posted January 19, 2014 Author Share Posted January 19, 2014 Alright, turns out PDO doesn't support multiple queries on default. Woops. This is solved. Link to comment https://forums.phpfreaks.com/topic/285482-running-query-in-phpmyadmin-gets-results-however-not-in-php/#findComment-1465723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.