If statement not inserting THIS item added to a lists; into the lists
MYSQL table... PHP/JQUERY/
How do I get php to figure out which ID is in an array but not in a MySQL
Database table?
I have 2 tables (record, records1)with the exact same column names
(recordID, recordText, recordListingsID); records1 is the actual ranking
list of an entire database table and records is a search for select items
from the main database table.
I have an update process that makes the database ListingID equal array
listingID. So I placed an if statement into to my update.php to insert a
drop item into the table but it caused the search list to update their
listing instead of records1. I created a separate insertDB.PHP and placed
it at the top. Now I know it is the insertDB.php that is causing issues,
specifically the iF and selection of the row to be transferred from
mainRecords to records1.
Working update.php
require("db.php");
require("insertDB.php");
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray = $_POST['recordsArray'];
if ($action == "updateRecordsListings"){
$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {
$query = "UPDATE records1 SET recordListingID = " . $listingCounter .
" WHERE recordID = " . $recordIDValue;
mysql_query($query) or die('Error, insert query failed');
$listingCounter = $listingCounter + 1;
}
echo '<pre>';
print_r($updateRecordsArray);
echo '</pre>';
echo 'If you refresh the page, you will see that records will stay just as
you modified.';
}
I know this following is wrong I am asking help because this is my third
week learning programming, so... i am here seeking knowledge (SORRY)
insertDB.php (ERROR)
require("db.php");
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray2 = $_POST['recordsArray'];
if ($action == "updateRecordsListings"){
foreach ($updateRecordsArray2 as $recordIDValue) {
if (!"SELECT recordID from records1 WHERE recordID = " . $recordIDValue){
$sql = "INSERT INTO records1 SELECT * FROM records WHERE ID =" .
$recordIDValue;
mysql_query($sql);
}
echo 'Item has been inserted into list.';
}
The currently produces a result in the array which I had prior to the if
statement. The position in the array is dictated in recortds1 by the other
rows but no insertion.
What I am seeing on screen...
I added or die to fix the repeating statement but that is all it does now
die. If there is an easier way to transfer an array item to trigger a
verification of if this item is already in the tables database please
leave a link or a the words I should be searching for and let me know.
I was looking into jquery receive but it will still require an if
statement like above so any help is appreciated.
No comments:
Post a Comment