0

Here's the line I'm having issues with:

array('jsonrpc' => '2.0', 'id' => 1, 'method' => 'getExchangeAmount', 'params' => array(array('from' => 'BTC', 'to' => 'LTC', 'amount' => '1'),array('from' => 'BTC', 'to' => 'ETH', 'amount' => '1')))

This is the specific part of the line I'm having issues with:

array(array('from' => 'BTC', 'to' => 'LTC', 'amount' => '1'),array('from' => 'BTC', 'to' => 'ETH', 'amount' => '1'))

Basically I'm using this script to compare prices of cryptocurrencies. The problem is that right now I'm having to enter all of them into the script manually.

However, I have a database table (trade_stats) that I'd prefer to get the details from.

Here's its layout:

id   incoming   outgoing
1    BTC        ETH
2    BCH        LTC
3    ETH        BCH

What I'm wanting to do is pull the rows from my database and use them in the script, but I can't seem to figure out how to create a multi-dimensional array.

Any help or pointers in the right direction would be great.

1
  • I can't see how that dataset might become a multidimensional array. What might the array look like? Commented Jul 17, 2018 at 23:13

1 Answer 1

1

I hope this helps you

<?php
$conn=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
if (!$conn) {
    die("Error Connecting To Database: ".mysqli_connect_error()."<br/>");
}
$sql="
SELECT * FROM trade_stats 
";
$result=mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0) {
    while($row=mysqli_fetch_assoc($result)) {
        $from=$row['incoming'];
        $to=$row['outgoing'];
        //$amount=$row['???'];
$array=array();
array_push($array, array('from' => $from, 'to' => $to, 'amount' => '1'));
print_r($array);
    }
}

?>

I didn't set a value for mysqli connect so you can edit it yourself and suit it for your database. +I don't know which column is for ((amount)) so I set 1 value for it.You can edit it yourself.

If you had any questions or if the code is not working as you wanted tell me I will edit it :)

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.