Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Edit: I'm going to post this anyway, even if I started writing it before your last reply, and you have since indicated there is more than one value/matching rows. If you were to post some sample results and indicate what part of it is duplicated, someone can probably help. We don't know what different types of data there are for any one user_id, don't have your database to test with, don't have or don't want to setup wp, and don't know what result you are getting. Edit: As to your last post, of course. What value is present in the data that can be used to identify the latest value?
  2. You need to add - AND um2.meta_key = 'wp_capabilities'
  3. You can directly select the monthname instead - http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_monthname You would also use an order by gl_date term in the query to order the rows the way you want. To output a new monthname heading when it changes in the data, see this post - http://www.phpfreaks.com/forums/index.php?topic=349740.msg1650897#msg1650897
  4. Actually, you don't need ; right before a closing ?> tag. Your unexpected $end error is probably because you are using short open tags and they are not enabled on your server. Be constant and always use full opening <?php tags in your code so that your code will always be seen as being php code. Why are you using so many opening and closing php tags in your code? <?php if($players['is_banned'] == 1) { echo "<a href='profile.php?id={$players['id']}'>{$players['name']} (BANNED)</a>"; }else{ echo "<a href='profile.php?id={$players['id']}'>{$players['name']}</a>"; } Or even simpler - <?php echo "<a href='profile.php?id={$players['id']}'>{$players['name']} ",($players['is_banned'] == 1) ? '(BANNED)' : '',"</a>";
  5. You would need to post your current code and you should never repeatedly open and close a database connection on one page. It takes a relatively long time to make each database connection. Just open the connection before your first query and either let php close it when the script on the page ends or close it yourself somewhere after the last query. Edit: Also, did you refresh the form in your browser so that the changes made to the HTML where updated in the browser?
  6. Nested <form></form> tags are invalid HTML. For any one form, you must have only one opening <form ... > tag and one closing </form> tag.
  7. You would not use either (assuming you are using one query.) Your goal for any SELECT query is a single query that gets the rows you want in the order that you want them. Then, when you are iterating over the rows in your presentation logic, you output the data the way you want. For what you want, you would remember the category value and output a new section heading when the category changes. See this post - http://www.phpfreaks.com/forums/index.php?topic=349740.msg1650897#msg1650897
  8. If you use the following debugging statement in your code, it will be clearer how you would reference the values you want - echo "<pre>",print_r($output,true),"</pre>";
  9. So, this is solved, correct?
  10. The single-quotes that you are putting around each of the data values are part of the SQL syntax. They should only be present inside the query statement, not as part of each of your $firstname, $surname, ... data values.
  11. TRY the query in reply #12. It will give you the pairs of rows you state you want. However, you probably want to do a (self) JOIN to basically get one row per each user_id with all the information in it from the pairs of rows that have a s2member_level in the wp_capabilities row. This (using a join) would result in less logic because with two rows per user_id (what you are attempting now) you will need to test which of the two rows for each user_id you are dealing with as you loop through the result set. You will also need an order by term in the query so that the two rows having the same user_id are together in the result set.
  12. If this was a real application, you would display the price on the form, but you would not pass the actual price through the form. You would only perform a calculation using price information that is completely server-side.
  13. That's because you cannot do greater-than/less-than comparisons on dates unless they are all in the proper format. Someone has already stated that and provided links to pages that explain why this is so and even to some code you could examine to see how you would loop over the dates for a selected month and test if your data has an event for any day in that month. The link I posted that eventually takes you to the post that starts - 'A slight bit of number/string comparison theory' is to some information that you learned in about the 4th grade when comparing integer numbers, but applied to a formatted date string. Without knowing what your database values are and what the value is in your $dateToCompare variable, it is not possible to help you with the latest symptom. Also, your WHERE clause in your query is just a TRUE value and is retrieving all the data in your table, that you are then trying to filter/match in your php code. You would never want to do that in a real application.
  14. Those errors mean that the coded did not match any of the order information. Either the code is doing something wrong or for the specific response being processed, the data was not expected or the status code wasn't for a successful order.
  15. New keep arrays - $keep_main = array( 'shipping_','first_name','last_name','email','phone','address1','address2','city','zip','collection-delivery','eshop_payment','amount'); $keep_order = array('item_name_','quantity_','amount_'); New matching logic - foreach($data as $key=>$value){ $base_key = preg_replace('/(_\d+)$/','_',$key); if(in_array($base_key,$keep_main)){ // normal template item $tpl[$base_key] = $value; } if(in_array($base_key,$keep_order)){ // order/repeating template item $otpl[$base_key][] = $value; } }
  16. The moral of the story being, if the OP had simply researched and read the php.net documentation for the basic information he is asking someone else about, he can get the full story from the official source of that information, in much greater detail and accuracy then what he will get in the few 10's or few 100's of words that someone will take the time to write in a forum reply.
  17. See this - http://www.phpfreaks.com/forums/index.php?topic=350918.msg1656495#msg1656495
  18. If I were to write that code today, I would split the $keep array into two arrays and then use two different if(in_array()){} statements, in place of the existing in_array, the array_search, and the if($pos<12){}else{} logic.
  19. I would use a template - <?php // Note: the index values in this array have significance. Index values 0-11 correspond to main template tags. Index values 12-14 correspond to repeating order template tags. $keep = array( 'shipping_','first_name','last_name','email','phone','address1','address2','city','zip','collection-delivery','eshop_payment','amount', 'item_name_','quantity_','amount_'); $main_template = "shipping_1: {shipping_} name: {first_name} {last_name} email: {email} phone: {phone} address1: {address1}, {city}, {zip} collection-delivery: {collection-delivery} eshop_payment: {eshop_payment} order: {order} amount: {amount} "; $each_order_template = "{quantity_} x {item_name_} {amount_} "; foreach($p->ipn_data as $key=>$value){ $base_key = preg_replace('/(_\d+)$/','_',$key); if(in_array($base_key,$keep)){ // data (assoc) key found $pos = array_search($base_key, $keep); // get corresponding index (index 0-11 are normal items, 12-14 are repeating items) if($pos < 12){ // normal template item $tpl[$base_key] = $value; } else { // order/repeating template item $otpl[$base_key][] = $value; } } } // exchange (pivot) the order data rows and columns foreach($otpl as $key => $arr){ foreach($arr as $num=>$value){ $pivot[$num][$key] = $value; } } $tpl['order'] = ''; // build/populate the repeating order template foreach($pivot as $row){ $tpl['order'] .= preg_replace("/\{([^\{]{1,100}?)\}/e","\$row['$1']",$each_order_template); // populate template } // build/populate the main template $body = preg_replace("/\{([^\{]{1,100}?)\}/e","\$tpl['$1']",$main_template); // populate template echo "<pre>"; // display literal output for debugging echo $body; I changed the preg_replace slightly so that the trailing under_score _ is kept so that the amount value can be distinguished from the amount_n values.
  20. <?php $keep = array('quantity','amount'); // fields to keep $body = ''; foreach($p->ipn_data as $key=>$value){ $base_key = preg_replace('/(_\d+)$/','',$key); // get the base key w/o the _nn if(in_array($base_key,$keep)){ // test if the base key is in the keep array $body .= "\n$key: $value"; // add the original key/value to the body } } echo '<pre>',$body,'</pre>'; // show the results for demo purposes
  21. I would use a preg_replace to remove any _n sequence numbers at the end of the $key value, leaving you with the base field name. You could then use an in_array statement to match only those field names that you want.
  22. @alpha1, I have looked more at your code (the posted code is only for your main page) and I'm not even sure why you think using a second database connection is needed. All your queries are (or should be) SELECT queries on different tables in the same database. The only thing you could accomplish by having database connections with different privileges would be to restrict the type of queries that can run. You do need to make your existing code more efficient. Opening and closing any database connection multiple times in the code on one page takes a lot of time (for the opening part.) For the code you posted, you should make the database connection once, before the first query statement, and then either let php close that connection automatically when the script on that page ends or you can close it yourself after you have made the last database call. Read the next paragraph about where exactly your last database call is occurring at (it's not anywhere near the createoptions() function definition.) Concerning your createoptions() function definition and the database connection that you are making right before that function definition. That's not doing what you think. The function definition is just the definition. You can put it anywhere in the code on that page. What matters is where you call the function. It's where you put the createoptions("Make", "Make_id", "Make"); statement that you would need the database connection to be present. But as already stated, you should only be opening one single database connection in the entire code you posted. Edit: Here's a hint based on where you are calling the createoptions() funciton at on your page and php errors on your page. Because you calling the createoptions() function inside of a HTML <select> .... </select> tag but outside of any <option></option> tag, any php errors that are being output will likely only appear in the 'view source' of the page in your browser.
  23. Doesn't matter where he puts the data while the php code is running, there are separate http requests being made to one (or more) .php page(s) that do and output something different for each separate http request.
  24. So, is that code you posted, for your select.php page, that your ajax http requests go to? If so, there's no code there to distinguish if the request is from the ajax to return select menu data or if it is the request for the main page. Every http request to your page is completely separate. When you request the main page, that is one http request. By the time you see the page being rendered in your browser the php code on the server that is outputting that page has finished and any database connection it made has been automatically closed. When the jquery on that page makes the http requests to get the chained-select data, those are completely separate http requests and any connection you make in the php code that is servicing those requests is also automatically closed by the time the select menus have been built and rendered in the browser.
×
×
  • 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.