1

I am building a custom part builder and I am trying to make it search the MySQl Database by the Part Number that is generated and then output the price into cell in a table. I can't figure out how to make it search by the Part Number that is generated and output the price. The Part Number is generated by Javascript but an example part number would be 133-FTHxFTH-075-N1-00. Here is my Ajax script

var request = $.ajax({ url: "http://localhost/filenamehere.php", type: "post", data: "partnumber" }); request.done(function (response) { document.getElementById("price1").innerHTML = response; });

Here is my PHP Code

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT 'LDS_Price_$' FROM list where 
Part_Number=**This is wher the generated part number would go** ");

echo "<table border='1'>
<tr>
<th>LDS Price $</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['LDS_Price_$'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>`
2
  • What have you tried? Show us the code? Commented Sep 20, 2017 at 14:39
  • Your filenamehere.php needs to connect to the database, run the query and return the results. Commented Sep 20, 2017 at 14:40

1 Answer 1

1

If your php file si returning just the price in plain text...

myPartNumber = '133-FTHxFTH-075-N1-00';

$.ajax({
    type: 'POST',
    url: "http://localhost/filenamehere.php",
    data: { partnumber: myPartNumber },
    dataType: 'html',
    async: true,
    success: function(data) {
        $('#price').html(data);
    }
});

I hope it helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.