How do you find information on the ID line?



  • I'm very new to mysql and php, and I've got the data in my table. Let's say I already have a ready table buyorders of species:

    order_id order_desc order_amount

    1 purchase of test item 1999

    order_id - id my order, order_desc - description of order, order_amount - price of order. How do you find a id order line and put order_desc in the $description, and order_amount in $amount?

    I tried the option:

    <?php
    $order_id;
    $order_desc;
    $order_amount;
    

    $connect = mysqli_connect('localhost','root','пароль','orders');

    if(isset($_GET["id"])){

    $order_id = $_GET["id"];
    

    }

    $result = $connect->query("SELECT order_amount FROM buyorders WHERE order_id = '{$order_id}'");
    $result = mysqli_fetch_array($result);
    echo $result;

    id in this case comes from a search line and enters a variable, but it does not work! Makes the next mistake.

    Array to string conversion in /var/www/site.site/pay/test.php on line 18
    Array



  • mysqli_fetch_array() returns the mass in which each element is a line from the database and is a set of columns from this line where the key is the name of the column of the SELECT request and the meaning of the column.

    It is therefore possible to do so:

    <?php
    $order_id;
    $order_desc;
    $order_amount;
    

    $connect = mysqli_connect('localhost','root','пароль','orders');

    if(isset($_GET["id"])){

    $order_id = $_GET["id"];
    

    }

    $result = $connect->query("SELECT order_amount, order_desc, FROM buyorders
    WHERE order_id = '{$order_id}'");
    $result = mysqli_fetch_array($result);
    $order_desc = $result[0]['order_desc'];
    $order_amount = $result[0]['order_amount'];
    echo $result;



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2