SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    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:

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

    while(
    $row mysqli_fetch_array($result))
      {
        echo 
    "<table border='1'>
    <tr>
    <th>Apples</th>
    </tr>"
    ;
      echo 
    "<tr>";
      echo 
    "<td>" $row['apples'] . "</td>";
      echo 
    "</tr>";
    echo 
    "</table>";

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

    <table border='1'>
    <tr>
    <th>Apples</th>
    </tr><tr><td>10</td></tr></table><table border='1'>
    <tr>
    <th>Apples</th>
    </tr><tr><td>5</td></tr></table>


    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

Bookmarks

Posting Permissions

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