SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    0 Post(s)
    0 Thread(s)

    Red face How to use $result from mysqli_query to perform calculation

    Hi all,

    I've just started a new job and have quite a bit of free time available and thought it would be a good idea to use it productively so i thought i would have a poke and prod and try to learn PHP with MySQL.

    I've made good progress this week, connecting to db's, creating tables, using SELECT, UPDATE, WHERE but have hit a little brick wall when i've tried to do the following.

    PHP Code:

    mysqli_query($con"SELECT apples FROM users2 WHERE username='$_POST[user1]'
                         OR username='
    $_POST[user2]' ORDER BY apples DESC");

    $row mysqli_fetch_array($result))
    "<table border='1'>
    "<td>" $row['apples'] . "</td>";

    I get what i want and expect in that i get a table with the results i asked for.

    <table border='1'>
    </tr><tr><td>10</td></tr></table><table border='1'>

    I've had a brainwave/brainfart however of using $result to perform a small calculation. Such like user1's apples minus users'2 apples then display that result, so somehow I have to get the values out of $result and work with them. If i can't use $result from the above MySQL statement or my PHP syntax how could i do it differently?

    I am grateful for any pointers in the right direction.

    I hope this makes sense!

    Many Thanks.
    Last edited by b9rry; Jun 27, 2013 at 09:29. Reason: spelling

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts