Zaffar Saffee
Zaffar Saffee

Reputation: 6305

mysql_result resulting error in php

I am just shifting my database from MS-Access to mysql

I am using the following code (part of related code only) to retrieve data from mysql

$con = mysql_connect("localhost","abc","abc@123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


  $conn= mysql_select_db('xyz', $con);
if (!$con) {
    die ('Can\'t connect to database : ' . mysql_error());
}

$sql="SELECT * FROM Inventory where Text5='y' OR Text5='Y'  ";
$rs=mysql_query($sql);
if (!$rs)
  {exit("Error connecting database,,,");}

while (mysql_fetch_row($rs))
//while (!$rs->EOF)
  {
        $ASIN=trim(mysql_result($rs,"ASIN"));

        $LocalSKU = trim(mysql_result($rs,"LocalSKU"));

        //$ASIN=trim($rs->fields[120]);
        if(trim($ASIN)!=""){
            //include('funtions.php');
            $shipArray = shipingPrice($ASIN);
            $Price=round((mysql_result($rs,"Price")),2);
            $Price2=round((mysql_result($rs,"Price2")),2);  

but when I run the script I get the following error message

Warning: mysql_result() expects parameter 2 to be long, string given in C:\wamp1\www\nathan\amazonPrice.php on line 67

basically, from the query result, I want to select the value of ASIN and LocalSKU fields to process it further..

can somebody suggest me what I am doing wrong here?

Upvotes: 0

Views: 2179

Answers (1)

Marc B
Marc B

Reputation: 360742

http://php.net/mysql_result

The second parameter of mysql_result is the row you want. It's NOT a string field.

Your code is rather horrible. You could vastly simplify it with:

$row = mysql_fetch_assoc($rs);
$price = $row['price'];
$pric2 = $row['price2'];
etc...

Upvotes: 4

Related Questions