Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how to check conditions with mysql and php ...I have two variables, $isbn and $f

ID: 3935631 • Letter: H

Question

how to check conditions with mysql and php

...I have two variables, $isbn and $formatQuantiy... Here is my problem before updating the database I need to check a few condition 1. check if isbn exists, if it does just update $formatQuantiy, if it does not create a column with isbn as primary key 2. $formatQuantity could be softcover,hardcover, or ebook...I need to update the quantity of the right column so if format is softcover I need to add 1 to the current value of column softcover purchase.. Here is my code... P.s I know how to do everything else but I don't know how to check the condition with MySQL

Explanation / Answer

Hi Added comments starting with //

$fields = mysql_list_fields($db, $selection);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {$field_array[] = mysql_field_name($fields, $i);}
//here checking that column is exists or not
//if not there adding that column to table

if (!in_array('isbn', $field_array))
{
$result = mysql_query('ALTER TABLE selection ADD isbn VARCHAR(10)');
}