Data insertion mess up in mysql database using php
Posted: Fri Nov 06, 2009 3:13 am
Hi i have a question regarding data inserts into mysql using php functions.
I use the joomla cms and trying to create a component.My table has 2 fields
id (primary key,int , auto increment)
link (varchar)
When i try to save a new link in joomla backend using this code
where $link is
everything works fine. BUT if i delete one or more rows using
where $arrayIDs is
data is inserted in a weird way .For example my table looks like
id link
4 link4
3 link3
2 link2
1 link1
Its like everytime i use the deleteLinks() the sorting changes from ascending/descending to descending/ascending even though i dont use any sorting.Any ideas?
If u need more info about joomla functions let me know.
Thanks in advance
I use the joomla cms and trying to create a component.My table has 2 fields
id (primary key,int , auto increment)
link (varchar)
When i try to save a new link in joomla backend using this code
Code: Select all
function saveLink($link)
{
$googlemapTableRow =& $this->getTable('googlemap');
// Bind the form fields to the googlemap table
if (!$googlemapTableRow->bind($link)) {
JError::raiseError(500, 'Error binding data');
}
// Make sure the link record is valid
if (!$googlemapTableRow->check()) {
JError::raiseError(500, 'Invalid data');
}
// Insert/update this record in the db
if (!$googlemapTableRow->store()) {
$errorMessage = $googlemapTableRow->getError();
JError::raiseError(500, 'Error binding data: '.$errorMessage);
}
//If we get here and with no raiseErrors, then everythign went well
}
where $link is
Code: Select all
$link = JRequest::get( 'POST'); $link['link']=htmlspecialchars(JRequest::getVar('link',null,'default',string,JREQUEST_ALLOWRAW), ENT_QUOTES, 'UTF-8');Code: Select all
function deleteLinks($arrayIDs)
{
//foreach(ids as $arrayIDs){
$query = 'DELETE FROM #__googlemap WHERE id IN ('.implode(',', $arrayIDs).')';
$db = $this->getDBO();
$db->setQuery($query);
if (!$db->query()){
$errorMessage = $this->getDBO()->getErrorMsg();
JError::raiseError(500, 'Error deleting greetings: '.$errorMessage);
}
}Code: Select all
$arrayIDs = JRequest::getVar('cid', array(), 'default', 'array' ); //Reads cid as an arrayid link
4 link4
3 link3
2 link2
1 link1
Its like everytime i use the deleteLinks() the sorting changes from ascending/descending to descending/ascending even though i dont use any sorting.Any ideas?
If u need more info about joomla functions let me know.
Thanks in advance