Jump to content

[SOLVED] how to display value of a mysql resource id


aconite

Recommended Posts

im running a mysql query in php

the result of the query is saved in $bal_account.in the next line i  want to display the value (string) of this  variable.

i have tried

echo $bal_account

but this displays the resource id#

wht shld i do???

Link to comment
Share on other sites

$bal_dest=mysql_query("select balance FROM account where account2='$theDest'");

 

$credit=($bal_dest+$theAmmount);

 

echo"destination  :";

echo'$bal_dest';

 

mysql_query("update account set balance= $credit where account2=  $theDest");

 

 

 

the output i get is

destination :Resource id #6

 

now i want to add $theAmmount(i.e.=20) to the integer/float value of $bal_dest.but i get

$credit=26 i.e. it adds 20 and 6

 

 

the balance filed in account table is float type and has the value 100 for this particular account.

Link to comment
Share on other sites

There are 2 posts in the FAQ/Code Snippet Repository that deal with retrieving info from MYSQL.

 

Post1 Post2

 

In your example you could do something similar to

 

<?php
$result = mysql_query("select balance FROM account where account2='$theDest'");
$row = mysql_fetch_assoc($result);
$bal_dest = $row['balance'];
$credit=($bal_dest+$theAmmount);

echo "bal dest: $bal_dest <br />\ncredit: $credit";
?>

 

You should be shown some examples of how to display query errors in one of the Faq Posts. If you have additional PHP problems similar to this one they should be directed to the PHP-Help forum.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.