answersLogoWhite

0


Best Answer

That will depend on the relationship between the two tables. Assuming it's a simple link between the two tables, then it can be done pretty easily.

For example, take two tables, "nuts" and "bolts". Perhaps you would want to compare the price per quantity of each of those, and that value is stored in the table. You could do it this way:

...

$query = mysql_query("SELECT nuts.price AS nutprice, bolts.price as boltprice FROM nuts JOIN bolts ON nuts.quantity = bolts.quantity");

while( $data = mysql_fetch_array($query)){

do_comparison($data['nutprice'], $data['boltprice']);

}

...

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Comparing a field from a table with a field from a different table and using PHP and MySQL?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you store and retrieve pictures in MySQL database?

The best thing to do is store them in a longblob field in your MySQL table.


What is MyISAM in MySQL?

MyISAM is the default table engine in the MySQL database.


Can you join a table to itself?

Yes. In MySQL you can join a table to itself. You must use different alias name for each instance.


What is MySQL insert command?

The INSERT command in MySQL allows you to enter a new row of data to a table in your database.


How do you create a table in dreamweaver?

using the mysql command "create table table_name" we can create a table in dreamweaver.


How do you retrieve 10 records from table in mysql?

For work with mysql database make use of software below to open/read/scan/export-import mysql data


How can you create a MYSQL table?

A good place to find tutorials on how to make a MYSQL table is tutorials point. It will show how to create the table as well as give many examples. It also has many other related tutorials.


How do you retrieve data from one MySQL table and create another MySQL table with the same data in it using PHP?

Execute a SELECT INTO statement on the mysql database: INSERT INTO destination_table (id, first_name, last_name) SELECT id, first_name, last_name from source_table;


How do you select unique values from a MySQL database?

Use the SQL Query below to get unique or distinct values for a field in a MySQL Table. You can choose different values for one or more columns with SELECT DISTINCT(column name) FROM your table name. The names of the columns must be separated by a comma. To learn more about data science please visit- Learnbay.co


What is the role of the insert command in MySQL?

The INSERT statement in MySQL is used to add data to a table. The INSERT INTO command inserts one or more rows into a MySQL table. For single row insertion you need to use the following syntax: INSERT Into table_name(column_1,column_2,column_3) VALUES(value_1, value_2, value_3); To speed up the process, you can use additional MySQL database management tools. For example, in dbForge Studio for MySQL, you can use the Generate Script as feature to insert one or more rows into a MySQL table.


How do you create a TABLE in MySQL?

To create a table in MySQL you will need to use the CREATE TABLE function. This is simple enough to use, a simple example of creating a users table is below, it has a unique id (Primary Key) with a unique username and a password field (which I would recommend storing as an MD5). CREATE TABLE users (id INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , username VARCHAR( 16 ) NOT NULL , password CHAR( 32 ) NOT NULL , UNIQUE ( username ) );


What command is used to remove a table in MySQL?

Please refer to the related links section which points to the correct page of the on-line MYSQL manual.