Jump to content

Please help.. any ideas on what I am doing wrong?


seeoneomen

Recommended Posts

All night long working on ONE problem and making ZERO progress. I wrote something and it works great, but only when the argument is written and not dynamically pulled. It makes no sense at all. I can echo the sent argument from the function but it does not exist in the string in the function! For instance:

 

Cats List = sql->data->null(SELECT * FROM ‘this table’ WHERE ‘id’ = absinto($arg), ARRAY_A);

// In this line $arg returns nothing. I can replace it with the number of the actual argument and it works great.

// but get this, on the very next line I can do this Echo absint($arg);

// and blam it fires back the sent argument. Am I going crazy or what!?! 

Link to comment
Share on other sites

Is this some psuedocode language you've made up, because that is not php syntax.

 

Provide a real code snippet if you would like us to try and help you understand what is going on.

 

If you are trying to pass an interpolated string as an argument to a function, and that interpolated string includes a function call, no that will not work.  You would have to concatenate the string together with the function calls.

Link to comment
Share on other sites

Thanks for the reply, here is my actual code:

 

// This is a loop that outputs category images and titles.

  <div class='wpsc_category_details'>
    <h3><?php _e('CATEGORIES','memahama'); ?></h3>
    <div class="wpsc_category_details_inner">
      <ul class="main_categories">
      <?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> 1)); ?>
      <li><a href="<?php wpsc_print_category_url();?>" title="<?php wpsc_print_category_name();?>"><?php wpsc_print_category_image(32, 32); ?><?php wpsc_print_category_name();?></a></li>
      <?php display_top_subcategories(); // this outputs the subcategories?>
      <?php wpsc_end_category_query(); ?>
      </ul>
    </div>
  </div>

 

// This code is in a file full of helper functions

function display_top_subcategories() {	
global $wpdb;
$category_id = 13; //WORKS
//$category_id = wpsc_return_category_id(); //DOES NOT WORK
$category_list_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '".absint($category_id)."'  ORDER BY 'nice-name'";
$category_list = $wpdb->get_results($category_list_sql, ARRAY_A);
  if($category_list != null) {
  $output = "<ul class='subcategories'>";
    foreach($category_list as $subcategory) {
		$output .= "<li><a href='".wpsc_category_url($subcategory['id'])."'>".stripslashes($subcategory['name'])."</li>";
	}
	$output .= "</ul>";	
}	
echo $output;
}

 

Im very confused as to why wpsc_return_category_id() cannot be used to get the $category_id. I have tried other methods but this is really the most direct. It should be noted that wpsc_return_category_id() actually works. I can echo it, but not pass it to the SQL query.

Link to comment
Share on other sites

I have commented out $category_id = wpsc_return_category_id(); because it does not work. The line above it is not commented out and instead has $category_id = 13 as it is the number for one of the categories i need sub categories from. I have this there for testing purposes, commenting and uncommenting to try the different variables. Basically its like this :

 

 

$category_id = wpsc_return_category_id();

Does NOT work.

 

$category_id = 13;

WORKS

 

To prove that wpsc_return_category_id() works I am doing this:

function display_top_subcategories($category_id) {	
global $wpdb;
$category_id = wpsc_return_category_id(); 
$category_list_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '".absint($category_id)."'  ORDER BY 'nice-name'";
$category_list = $wpdb->get_results($category_list_sql, ARRAY_A);
  if($category_list != null) {
  $output = "<ul class='subcategories'>";
    foreach($category_list as $subcategory) {
		$output .= "<li><a href='".wpsc_category_url($subcategory['id'])."'>".stripslashes($subcategory['name'])."</a></li>";
	}
	$output .= "</ul>";	
}	
echo $category_id;

}

This returns the category ID for each queried category.

Link to comment
Share on other sites

Right after:

 

$category_list_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '".absint($category_id)."'  ORDER BY 'nice-name'";

 

Add var_dump($category_list_sql): die();

 

What is the output?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.