Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Your forgot to tell us what error or symptom you saw in front of you that leads you to believe your code isn't working. Without that information, since we are not standing right next to you, it's a little hard to narrow down the dozen different things that could be wrong with any piece of code to the one or two actual things to check.
  2. This is secondary to the problem you are having, but by putting the $row_id variable directly into the query being prepared, you are allowing sql injection, not preventing it. One of the main points of using prepared query statements is to prevent sql injection. You would put a place holder into the query for the id value, then supply the actual value at the time the query is executed. Edit: ^^^ Which I had already posted at the end of your last thread - http://forums.phpfreaks.com/topic/271784-show-row/#entry1398388
  3. Topic locked to prevent replies that should be in the original thread. @jazzman1, I moved your post from this thread to the original thread.
  4. If you are getting a notification email with a problem with the link in it, please start a thread in the PHPFreaks Questions, Comments section - http://forums.phpfreaks.com/forum/23-phpfreakscom-questions-comments-suggestions/ Copy/paste the link from the notification email so that an admin can find what is wrong with it.
  5. Your thread didn't disappear, unless you mean that you couldn't find it by looking under your profile (which doesn't work as it should) - http://forums.phpfre...configphp-file/
  6. If you look at the code I posted, you will see that I modified the code in his function to use the modified data structure. In fact, the code I posted is a working example. Put it into a .php file and play with it to see what the code is doing.
  7. You should define the fields (legend text, field name, field type) in an array (or a database table), then simply loop over the list of field definitions and build the form using php code.
  8. Change - $data[$parent][] = array('id'=>$id, 'name'=>$name, 'number'=>$number); To - $data[$parent][$id] = array('name'=>$name, 'number'=>$number,'total'=>0);
  9. The data would be in an array or a database. Then you would use the entered value to loopup/find the result.
  10. That comes from the column name that was selected in the query statement. Unfortunately, someone broke a rule of clear code writing and used the extract statement to magically produce php variables in that code. You would normally, and less magically, use $row['product'] in that code.
  11. You would need to iterate over the data to produce the totals, then display the result - <?php // sample data - $data[null][1] = array('name'=>'Europe', 'number'=>0,'total'=>0); $data[1][2] = array('name'=>'BG', 'number'=>8,'total'=>0); $data[2][3] = array('name'=>'Sofia', 'number'=>5,'total'=>0); $data[2][4] = array('name'=>'Varna', 'number'=>2,'total'=>0); $data[3][5] = array('name'=>'Mladost', 'number'=>4,'total'=>0); $data[4][6] = array('name'=>'Chaika', 'number'=>9,'total'=>0); // additional test values - /* $data[2][7] = array('id'=>7, 'name'=>'abc', 'number'=>1,'total'=>0); $data[1][8] = array('id'=>8, 'name'=>'def', 'number'=>3,'total'=>0); $data[8][9] = array('id'=>9, 'name'=>'defg', 'number'=>5,'total'=>0); $data[null][10] = array('id'=>10, 'name'=>'ghi', 'number'=>0,'total'=>0); $data[10][11] = array('id'=>11, 'name'=>'ghijlk', 'number'=>33,'total'=>0); */ // this function produces the totals only function totalHierarchy(&$arr, $parent, $bc=''){ if (isset($arr[$parent])) foreach($arr[$parent] as $id=>$rec){ // form a bread-crumb to reference the total elements $p = is_null($parent) ? 'n':$parent; // convert the null parent to a value that can be seen for debugging $bread = ($bc != '') ? '|' : ''; // make bread-crumb (the incoming $bc value is not altered so it has the correct value for the duration of the loop at any recursion level) $bread .="{$p}_{$id}"; // form bread-crumb for the current recursion // add number to appropriate totals - $parts = explode('|',$bc.$bread); // the existing bread-crumb + bread-crumb for the current recursion foreach($parts as $crumb){ list($indexa,$indexb) = explode('_',$crumb); $indexa = $indexa == 'n' ? null : $indexa; // convert the 'n' back to null $arr[$indexa][$indexb]['total'] += $rec['number']; } totalHierarchy($arr, $id, $bc.$bread); } } // this function displays the information function displayHierarchy(&$arr, $parent, $indent=0){ $ind = $indent * 30; if (isset($arr[$parent])) foreach($arr[$parent] as $id=>$rec){ echo "<div style='width:300px; margin-top:5px; margin-left: {$ind}px; padding:5px; border:1px solid gray;'> {$rec['name']} - {$rec['total']} </div>" ; displayHierarchy($arr, $id, $indent+1); } } // call the recursive total function totalHierarchy($data, null); // call the recursive display function displayHierarchy($data, null);
  12. Your repost of this in the php forum section has been removed. Where exactly is the onclick= ... statement in the HTML on your page, because you cannot just put it in the middle of nowhere. It needs to be inside the HTML tag of something that can be clicked on - i.e. show us the actual code that reproduces the problem that you need help with.
  13. You would use a counter to determine when you close out one row and start the next - http://forums.phpfreaks.com/topic/11572-multi-column-results/
  14. See this link - http://dev.mysql.com/doc/refman/5.5/en/identifier-case-sensitivity.html
  15. There's almost never a reason (good or bad) to perform queries inside of a loop. You need to - 1) Execute one query that gets the records you need for one complete page. If you are trying to display data for one day, you would retrieve all the records that match that year/month/day. If you are trying to display data for one month, you would retrieve all the records that match that year/month. 2) Fetch all the records that the query matched and store them into a php array, using the datetime of the record as the array key. If you can have more than one 'event' on any datetime, you would make a two-dimensional array. $data = array(); while($row = mysql_fetch_assoc($dbslottimes)){ // if there can be only one event per datetime - $data[$row['your_datetime_field_here...']] = $row; // if there can be more than one event per datetime - $data[$row['your_datetime_field_here...']][] = $row; } 3) As you loop through the datetime slots to produce your output, form a datetime value of that datetime slot (in $datetime for the following sample code) and use that value to test/reference any data in the array you formed in step #2. To just test if there is data, you can use isset($data[$datetime]) or array_key_exists($datetime,$data). To reference the data - // if there can be only one event per datetime - if(isset($data[$datetime])){ echo $data[$datetime]['some_field_name_here...']; } // if there can be more than one event per datetime - if(isset($data[$datetime]) && is_array($data[$datetime])){ foreach($data[$datetime] as $row){ echo $row['some_field_name_here...']; } }
  16. When using the GET method for a form, the only get parameters that are put into the URL are from the form fields. You would need to use hidden form fields to pass any existing get parameters.
  17. Ummm. If your purchased code has a copyright by the author that prevents you from publishing/distributing it, which is likely, don't post it. Get help from the author.
  18. You would also need to tells us what symptom or error you got that leads you to believe that something doesn't work as expected, because we are not standing right next to you and don't know what you saw in front of you.
  19. A word about using prepared query statements. You prepare the query without any external data in it, using place-holders where the data actually goes, Then you either bind a variable with the data, bind the literal data value, or supply the data when the ->execute() method is called. By putting the variable holding the external data into the query statement in the ->prepare() method, that would prepare any injected sql as well.
  20. The ->fetchall() method returns the rows in an array. $results[0] is the 1st row (if any.) $results[1] is the 2nd row (if any.) If you have a column `name` you would reference the first row's value using -$results[0]['name'] The ->fetchAall() method is intend to be iterated over using php array functions. If you expect at most one row, use the ->fetch() method.
  21. I'm going to guess that your password field in the table isn't long enough to hold a the hashed value or the hashing method used when entering the password in the table isn't the same as what you are using in your login code. You actually should hash your password in your php code and put the hashed value into the query (this will prevent a plain-text password from being sent from php to mysql) and it will also allow you to echo/print out the actual complete query so that you can look at the values being put into it and compare them manually with the data you have stored in your database table, which is what you will need to do to find why the query isn't matching a row in your database table.
  22. If you are working with a date that includes the day of the month, you will need to account for leap year when switching years, since every year doesn't have a Feb 29th. If you are just working with the year or the year and month - <?php // get the submitted year or the current year as a default $year = (isset($_GET['year'])) ? (int)$_GET['year'] : date('Y'); // produce 'yearination' links (keeping any other get parameters that might be present) $year_links = ''; // previous link $_GET['year'] = $year-1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $year_links .= "<a href='?" . http_build_query($_GET, '', '&') . "'>-</a> "; // display current year $year_links .= " $year "; // next link $_GET['year'] = $year+1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $year_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'>+</a>"; ?> <style type="text/css"> a:link {text-decoration:none;} </style> <?php // output the links somewhere on your page echo $year_links;
  23. Since you didn't bother to state what symptom or error you get when you run the code, it's not possible to directly help you pin down which of the dozen different things the code or your form could be doing that leads you to believe your code isn't working like you expect. Care to share what happened in front of you when you ran your code?
  24. That actually means you WEREN'T logged in and your code allowed you to access the page. Read your logic - if (confirmed_logged_in() && $_SESSION['access'] == 0) redirect to some other page. What happens if the first term is false (not logged in), then you don't redirect either. What you are trying to do is - if logged in && access == admin, stay on the page. To complement that, you negate both conditions and use an || - if not logged in || access != admin, redirect.
  25. The form field name='...' attributes are the php $_POST['...'] variable names, so only $_POST['q1'], $_POST['q2'], and $_POST['q3'] can exist and only if one the radio buttons in a field with that name is selected.
×
×
  • 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.