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

Proper way for query functionality

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #11  
Old 04-10-2017, 04:58 PM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Proper way for query functionality

Yes of course... I totally missed that - duuuhhh.
I am more concerned if the var is empty or not. And with the - ne '' - I get that functionality.

Thank you again!!!

-S
__________________
Thanks.
Reply With Quote
  #12  
Old 04-12-2017, 05:17 PM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Proper way for query functionality

Hi guys, sorry for re-hashing this post.

As I previously mentioned I have everything wired up from product.php to product.tpl with a simple string being passed along. Now reverting to my original question about sending over a query to the tpl file.

If I am running a SELECT * query and assign it to the smarty var I can see the array or rows and the array of columns being passed along with a print_r. The trouble I am running into is, where do i run the foreach loop - in the php file or the tpl file? In addition, where do you stipulate the column's name of the data being retrieved in this type of setup - in this case image_path column?

Here's what I have so far:

PHP
PHP Code:
$q " SELECT * FROM some_table ";
$r func_query($q);
$smarty->assign('data'$r); 

TPL
PHP Code:
{foreach from=$data name=row item=t}
  {foreach 
from=$t item=z}
    <
img href="{$z}/>
  {/foreach}
{/foreach} 

At the moment, what I am getting is an img tag for every column in every row - and I understand why. But when I try to specify a certain column name, no matter where I do it, I can't get it to out put only that column for each of the rows. I've tried using column name as such ['image_path'] and also the index as such [0].

ALSO - For some strange reason, even the img path columns do not display the image properly. it shows the path saved in the db inside the href, but does not display the image on the page - strange. I can see the path is correct because with dev tools if I right click over the href and choose open in new tab, it opens the image with no issues.

Any input guys is really appreciated.

Thank you again.

-S
__________________
Thanks.
Reply With Quote
  #13  
Old 04-12-2017, 05:20 PM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Re: Proper way for query functionality

Tell us exactly what you want to display, plus where and we might be able to give you a solution...
__________________
xcartmods.co.uk
Reply With Quote

The following user thanks PhilJ for this useful post:
simetria (04-12-2017)
  #14  
Old 04-12-2017, 05:27 PM
  cherie's Avatar 
cherie cherie is offline
 

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

Default Re: Proper way for query functionality

You are correct in running the foreach in the tpl. We might need to see a sample output from print_r to help you pinpoint the proper foreach code. Off the top of my head I'm guessing you are looking for something like this:
Code:
{foreach from=$data item=p} <img href="{$p.image_path}" /> {/foreach}
As for image path not displaying an image you might want to post what you are seeing.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote

The following user thanks cherie for this useful post:
simetria (04-12-2017)
  #15  
Old 04-12-2017, 05:27 PM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Proper way for query functionality

I'm trying to retrieve the image paths from an image table (the maufacturers image table for this example) and then displaying the images in a page - I am using the product page just for testing purposes.
__________________
Thanks.
Reply With Quote
  #16  
Old 04-12-2017, 05:37 PM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Proper way for query functionality

Cherie, that did what I'm looking for, but the images still aren't rendering on the page. But the href paths are showing up correctly - see image.

http://www.simetriastudio.com/wp-content/themes/simetria/images/ex.jpg
__________________
Thanks.
Reply With Quote
  #17  
Old 04-12-2017, 05:42 PM
  cherie's Avatar 
cherie cherie is offline
 

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

Default Re: Proper way for query functionality

That shows ./ as the starting point which means from your current location. You probably need the full url. modules/Manufacturers/customer_manufacturers_list.php does it this way if that helps:

PHP Code:
$manufacturer['image_url'] = func_get_image_url($manufacturerid"M"$manufacturer['image_path']); 
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #18  
Old 04-12-2017, 05:43 PM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Re: Proper way for query functionality

There's probably a more efficient way, using joins on the initial query, but here's an example of how I do it, cobbled together from all the beautiful people on this forum.

Put this get_manufacturers.php in the root, noting...

Quote:
$manufacturers_limit = 12;
$manufacturers_sort = "random"; // random, name or orderby

Code:
<?php // PhilJ woz ere // https://forum.x-cart.com/showthread.php?t=75179&page=2 $manufacturers_limit = 12; $manufacturers_sort = "random"; // random, name or orderby //------------------------------------ if ($manufacturers_sort == "random") { $qry = "SELECT * FROM " . $sql_tbl["manufacturers"] . " WHERE avail='Y' ORDER BY RAND() LIMIT $manufacturers_limit"; } else if ($manufacturers_sort == "name") { $qry = "SELECT * FROM " . $sql_tbl["manufacturers"] . " WHERE avail='Y' ORDER BY manufacturer LIMIT $manufacturers_limit"; } else if ($manufacturers_sort == "orderby") { $qry = "SELECT * FROM " . $sql_tbl["manufacturers"] . " WHERE avail='Y' ORDER BY orderby LIMIT $manufacturers_limit"; } $result = db_query($qry); while ($result_row = db_fetch_array($result)) { $manufacturers[] = $result_row; } if ($manufacturers) { foreach($manufacturers as $key=> $manufacturer) $manufacturers[$key]["image_path"] = func_query_first_cell("SELECT image_path FROM $sql_tbl[images_M] WHERE id=".$manufacturer["manufacturerid"]); foreach($manufacturers as $key=> $manufacturer) $manufacturers[$key]["tmbn_x"] = func_query_first_cell("SELECT image_x FROM $sql_tbl[images_M] WHERE id=".$manufacturer["manufacturerid"]); foreach($manufacturers as $key=> $manufacturer) $manufacturers[$key]["tmbn_y"] = func_query_first_cell("SELECT image_y FROM $sql_tbl[images_M] WHERE id=".$manufacturer["manufacturerid"]); } $smarty->assign("featured_manufacturers",$manufacturers); ?>

In your PHP page...

Code:
if ($active_modules['Manufacturers']) { include './get_manufacturers.php'; }

Smarty...

Code:
{foreach from=$featured_manufacturers item=m name=m} <p><a href="manufacturers.php?manufacturerid={$m.manufacturerid}"><img src="{$m.image_path|default:'default_icon.gif'}" alt="{$m.manufacturer}" width="{$m.tmbn_x}" height="{$m.tmbn_y}"></a></p> {if $m.descr}<p>{$m.descr}</p>{/if} <p><a href="manufacturers.php?manufacturerid={$m.manufacturerid}">{$m.manufacturer|amp}</a></p> {if !$smarty.foreach.m.last}<hr>{/if} {/foreach}
__________________
xcartmods.co.uk
Reply With Quote

The following user thanks PhilJ for this useful post:
qualiteam (04-13-2017)
  #19  
Old 04-12-2017, 05:59 PM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Proper way for query functionality

Thank you guys, you've been SUPER helpful.
PhilJ I will give your suggestion a go and post back on the results.

Thanks again guys.

-S
__________________
Thanks.
Reply With Quote
  #20  
Old 04-17-2017, 12:39 PM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Proper way for query functionality

PhilJ,

I have implemented your code, and seems to be working good on the testing example I created, but if I try to move the code to the manufacturers' module/page, it displays things a bit differently. It seems to be also including the sidebar list as well - including the parameters defined in the backend. For example in the sidebar I have it so it only display 10 manufacturers, and on the actual manufacturers list php page it first displays those 10, then if displays the ones from your code. I tested this by changing the limit # in the get_manufacturers.php file. How can I omit the initial 10 since those are only targeted for the sidebar?

Thank you,

-S
__________________
Thanks.
Reply With Quote
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 02:35 PM.

   

 
X-Cart forums © 2001-2020