1

So, Im having a lot of trouble with executing a query in PHP. It executes well in phpmyadmin and gives me a neat list of results.

Here is the query I inserted into phpmyadmin:

SELECT RIGHT(`Pair`, LOCATE('_', REVERSE(`Pair`))-1) 
FROM `poloniex`
WHERE LEFT(`Pair`, 3) = 'BTC';

For example an entry in the Column Pair: BTC_NXT

The query should return NXT (everything right of the "_").

Now, when switching over to php while I haven't edited the query at all, I don't get any result. The dbconnection is already established; no problems on that front.

$query_get_pairs = "SELECT RIGHT(`Pair`,LOCATE('_',REVERSE(`Pair`))-1) FROM `poloniex` WHERE LEFT(`Pair`, 3) = 'BTC'";
$result_get_pairs = mysqli_query($dbc,$query_get_pairs);

var_dump($result_get_pairs) returns an empty array.

Summary:

  • poloniex is the table name.
  • Pair is the column name which contains values like "BTC_NXT". The query should give me NXT.
5
  • 3
    What does mysqli_error() say? Commented May 16, 2014 at 19:22
  • There's absolutely NO way that $result_get_pairs would be an empty array. mysqli_query returns either a mysqli statement handle, or a boolean FALSE to signify failure. Commented May 16, 2014 at 19:23
  • Do you mean mysqli_error($dbc)? That doesnt give me anything. Commented May 16, 2014 at 19:25
  • @Marc B it gives me a boolean FALSE indeed. Commented May 16, 2014 at 19:25
  • 1
    That means your query failed, and mysqli_error() would tell you why. Commented May 16, 2014 at 19:27

1 Answer 1

1

You are not fetching anything, your code should be like:

$query_get_pairs = "SELECT RIGHT(Pair,LOCATE('_',REVERSE(Pair))-1) FROM poloniex WHERE LEFT(Pair, 3) = 'BTC'";
$result_get_pairs = mysqli_query($query_get_pairs);
$myResult = mysqli_fetch_assoc($result_get_pairs);
var_dump($myResult);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.