Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Using an ID array to perform a db query

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-06-2017, 06:07 AM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Using an ID array to perform a db query

Hi all,

I'm trying to perform a single query to the db, in which I am using an array of IDs to insert in the WHERE clause. So far I've had mixed results, and this is the closest I've gotten to achieve what I am looking for.

PHP Code:
require './auth.php';

$prodId = array(177541775517756);
$ids implode(",",$prodId);

$qry "SELECT clean_url AS url FROM xcart_clean_urls WHERE resource_id IN ($ids) ";
$resultTst db_query($qry);

while (
$result_row db_fetch_array($resultTst)) {
   
$urls[] = $result_row;
   if ( 
$urls ) {
      echo 
$urls[0]['url'] . '<br>';
      echo 
$urls[1]['url'] . '<br>';
      echo 
$urls[2]['url'] . '<br>';
   }


THE RESULTS I GET (I get the actual urls):
urlforid17754

urlforid17754
urlforid17755

urlforid17754
urlforid17755
urlforid17756


How can I perform the same functionality, but only retrieve the 3 urls once?

Thank you all.

Serge
__________________
Thanks.
Reply With Quote
  #2  
Old 06-06-2017, 07:22 AM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Using an ID array to perform a db query

Ok, fixed it.
I will leave it here for anyone looking for something similar...

PHP Code:
require './auth.php';

$prodId = array(177541775517756);
$ids implode(",",$prodId);

$qry "SELECT clean_url AS url FROM xcart_clean_urls WHERE resource_id IN ($ids) ";
$resultTst db_query($qry);

while (
$result_row db_fetch_array($resultTst)) {
   echo 
$result_row['url'];
   
$urls[] = $result_row;

__________________
Thanks.
Reply With Quote
  #3  
Old 06-12-2017, 12:42 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default Re: Using an ID array to perform a db query

Simpler to use the built-in db functions (see include/func/func.db.php) and table references ($sql_tbl):

PHP Code:
$qry "SELECT clean_url FROM $sql_tbl[clean_urls] WHERE resource_id IN (".implode(',',$prodId).')';
$urls func_query_first($qry); 
func_query_column() is another good one that might be more of what you are looking for.

A more thorough reply might be to loop the productids and call func_get_resource_url() (see func.clean_urls.php), though that is more resource intensive, but should be fine for small lists of products.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote

The following user thanks cherie for this useful post:
qualiteam (06-13-2017)
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:44 PM.

   

 
X-Cart forums © 2001-2020