Get specific ads
on :July 19, 2022, 11:28 am #627
I have this code to fetch specific ads by ad number osc_query_item("id in (145,146,250,266)"); But the problem is that it only fetches one ad. Why is not all the specific ads fetched? Is there another better way or a specific job? Thank you
Re: Get specific ads
on :July 19, 2022, 9:21 pm #628
Try this:
$itemIds = array(8,9);//list of items id
$itemsPerPage = (Params::getParam('itemsPerPage') != '') ? Params::getParam('itemsPerPage') : 10;
$page = (Params::getParam('iPage') > 0) ? Params::getParam('iPage') - 1 : 0;
$view = View::newInstance();
$mSearch = new Search();
$mSearch->page($page, $itemsPerPage);
$mSearch->addConditions(sprintf( '%st_item.pk_i_id' , DB_TABLE_PREFIX) . ' IN (' . implode( ', ', $itemIds) . ')' );
$aItems = $mSearch->doSearch(true);
$view->_exportVariableToView('items', $aItems);
Re: Get specific ads
on :August 9, 2022, 7:23 pm #629
Quote from: calinbehtuk on July 19, 2022, 9:21 pmCode: [Select]
Try this:
Code: [Select]$itemIds = array(8,9);//list of items id
$itemsPerPage = (Params::getParam('itemsPerPage') != '') ? Params::getParam('itemsPerPage') : 10;
$page = (Params::getParam('iPage') > 0) ? Params::getParam('iPage') - 1 : 0;
$view = View::newInstance();
$mSearch = new Search();
$mSearch->page($page, $itemsPerPage);
$mSearch->addConditions(sprintf( '%st_item.pk_i_id' , DB_TABLE_PREFIX) . ' IN (' . implode( ', ', $itemIds) . ')' );
$aItems = $mSearch->doSearch(true);
$view->_exportVariableToView('items', $aItems);
thanks for your reply
I tested the code this wayCode: [Select]<?php
$itemIds = array(66,48,55);//list of items id
$itemsPerPage = (Params::getParam('itemsPerPage') != '') ? Params::getParam('itemsPerPage') : 10;
$page = (Params::getParam('iPage') > 0) ? Params::getParam('iPage') - 1 : 0;
$view = View::newInstance();
$mSearch = new Search();
$mSearch->page($page, $itemsPerPage);
$mSearch->addConditions(sprintf( '%st_item.pk_i_id' , DB_TABLE_PREFIX) . ' IN (' . implode( ', ', $itemIds) . ')' );
$aItems = $mSearch->doSearch(true);
$view->_exportVariableToView('items', $aItems);
osc_query_item($itemIds);
if( osc_count_custom_items() == 0) { ?>
<p class="empty"><?php _e('No Listings', 'epsilon') ; ?></p>
<?php } else { ?>
But the same problem is fetching only one ad
I may be wrong in the code
Is that correct
Thank you again
Re: Get specific ads
on :August 9, 2022, 8:19 pm #630
Why do you count custom items when you export items and why do you use custom items query when the items are already exported?
$itemIds = array(8, 9);
$itemsPerPage = (Params::getParam('itemsPerPage') != '') ? Params::getParam('itemsPerPage') : 10;
$page = (Params::getParam('iPage') > 0) ? Params::getParam('iPage') - 1 : 0;
$view = View::newInstance();
$mSearch = new Search();
$mSearch->page($page, $itemsPerPage);
$mSearch->addConditions(sprintf('%st_item.pk_i_id', DB_TABLE_PREFIX) . ' IN (' . implode(', ', $itemIds) . ')');
$aItems = $mSearch->doSearch(true);
$view->_exportVariableToView('items', $aItems);
if (osc_count_items() == 0) {
?>
<p class="empty"><?php _e('No Listings', 'epsilon'); ?></p>
<?php
} else {
while (osc_has_items()) {
//some code to export each item
echo osc_highlight(osc_item_title(), 100);
}
}
Re: Get specific ads
on :August 9, 2022, 8:45 pm #631
Thank you
you are creative
Works great
Thank you again![]()
Re: Get specific ads
on :August 10, 2022, 7:35 am #632
Is there a problem if I repeat the code on the same page
Also, when you repeat the code on the page, some elements are arranged
And some are not arranged, it may be because the code is duplicated on the page
Is it possible to repeat only part of the code and a fixed part to be assigned to all?
1-
<?php
$itemIds = array(8,9,15,44,33);
$itemsPerPage = (Params::getParam('itemsPerPage') != '') ? Params::getParam('itemsPerPage') : 10;
$page = (Params::getParam('iPage') > 0) ? Params::getParam('iPage') - 1 : 0;
$view = View::newInstance();
$mSearch = new Search();
$mSearch->page($page, $itemsPerPage);
$mSearch->addConditions(sprintf('%st_item.pk_i_id', DB_TABLE_PREFIX) . ' IN (' . implode(', ', $itemIds) . ')');
$aItems = $mSearch->doSearch(true);
$view->_exportVariableToView('items', $aItems);
if (osc_count_items() == 0) {
?>
<p class="empty"><?php _e('No Listings', 'epsilon'); ?></p>
<?php
} else {
while (osc_has_items()) {
//some code to export each item
echo osc_highlight(osc_item_title(), 100);
}
}
2-
<?php
$itemIds = array(5, 20,30,77);
$itemsPerPage = (Params::getParam('itemsPerPage') != '') ? Params::getParam('itemsPerPage') : 10;
$page = (Params::getParam('iPage') > 0) ? Params::getParam('iPage') - 1 : 0;
$view = View::newInstance();
$mSearch = new Search();
$mSearch->page($page, $itemsPerPage);
$mSearch->addConditions(sprintf('%st_item.pk_i_id', DB_TABLE_PREFIX) . ' IN (' . implode(', ', $itemIds) . ')');
$aItems = $mSearch->doSearch(true);
$view->_exportVariableToView('items', $aItems);
if (osc_count_items() == 0) {
?>
<p class="empty"><?php _e('No Listings', 'epsilon'); ?></p>
<?php
} else {
while (osc_has_items()) {
//some code to export each item
echo osc_highlight(osc_item_title(), 100);
}
}
3-
<?php
$itemIds = array(50, 25,33,79);
$itemsPerPage = (Params::getParam('itemsPerPage') != '') ? Params::getParam('itemsPerPage') : 10;
$page = (Params::getParam('iPage') > 0) ? Params::getParam('iPage') - 1 : 0;
$view = View::newInstance();
$mSearch = new Search();
$mSearch->page($page, $itemsPerPage);
$mSearch->addConditions(sprintf('%st_item.pk_i_id', DB_TABLE_PREFIX) . ' IN (' . implode(', ', $itemIds) . ')');
$aItems = $mSearch->doSearch(true);
$view->_exportVariableToView('items', $aItems);
if (osc_count_items() == 0) {
?>
<p class="empty"><?php _e('No Listings', 'epsilon'); ?></p>
<?php
} else {
while (osc_has_items()) {
//some code to export each item
echo osc_highlight(osc_item_title(), 100);
}
}
Thanks