seeoneomen Posted July 1, 2011 Share Posted July 1, 2011 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!?! Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/ Share on other sites More sharing options...
gizmola Posted July 1, 2011 Share Posted July 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/#findComment-1237235 Share on other sites More sharing options...
seeoneomen Posted July 1, 2011 Author Share Posted July 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/#findComment-1237339 Share on other sites More sharing options...
seeoneomen Posted July 1, 2011 Author Share Posted July 1, 2011 Any ideas? I'd really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/#findComment-1237372 Share on other sites More sharing options...
wildteen88 Posted July 1, 2011 Share Posted July 1, 2011 You have commented this line out //$category_id = wpsc_return_category_id(); //DOES NOT WORK Remove the // before $category_id If it still does not work then post the code for the wpsc_return_category_id() function Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/#findComment-1237385 Share on other sites More sharing options...
$php_mysql$ Posted July 1, 2011 Share Posted July 1, 2011 yeah wrong place to add a //comment :-D Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/#findComment-1237412 Share on other sites More sharing options...
seeoneomen Posted July 1, 2011 Author Share Posted July 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/#findComment-1237434 Share on other sites More sharing options...
gizmola Posted July 1, 2011 Share Posted July 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/240869-please-help-any-ideas-on-what-i-am-doing-wrong/#findComment-1237454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.