#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Laurens, SC ,US
    Posts
    20
    Rep Power
    0
    I know this must be something incredibly simple but since I don't know what that simple thing is,...

    I have created a table with a column "Price" defined as Decimal(10,2). There are two records for articles with prices of 99.95 and 14.95.

    Within PHP I have the following lines:

    $resulta = mysql_query("Select price from shop where article = '4'");
    if (!$resulta) {echo "An error occurred in query.n",exit;}
    echo "Result A price for article 4 is $resulta <br>";

    $resultb = mysql_query("Select price from shop where article = '5'");
    if (!$resultb) {echo "An error occurred in query.n",exit;}
    echo "Result B price for article 5 is $resultb<br>";

    $resultc = $resulta + $resultb;

    The page results are:

    Result A price for article 4 is 2
    Result B price for article 5 is 3
    Value in this field is 5

    While in mySQL via telnet the command "Select * from TABLE;" returns the correct results.

    Where have I gone astray? I have also tried integer and float.

    ------------------
    Thanks for the help.
    ebryan@lumenet.com
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    A mysql_query returns a 0 for an error or a postive result index, not the result of the query.

    Your code should look like this after the if:

    list($price)=mysql_fetch_row($resulta);
    echo "ResultA price for article 4 is $price <br>";

Similar Threads

  1. Inserting values into Date field
    By Husky in forum MySQL Help
    Replies: 1
    Last Post: February 16th, 2004, 06:33 PM
  2. setting default values in column field
    By arthats in forum MySQL Help
    Replies: 1
    Last Post: February 9th, 2004, 10:20 PM
  3. Query to choose different values in field
    By angrypanda in forum MySQL Help
    Replies: 2
    Last Post: January 30th, 2004, 03:48 PM
  4. Zip code validation
    By krwyth in forum MySQL Help
    Replies: 2
    Last Post: January 5th, 2004, 01:29 PM
  5. Replies: 1
    Last Post: December 16th, 2003, 03:03 AM

IMN logo majestic logo threadwatch logo seochat tools logo