
davidannis
Members-
Posts
627 -
Joined
-
Last visited
-
Days Won
2
Everything posted by davidannis
-
display column names from database in returned values table
davidannis replied to Juarez's topic in PHP Coding Help
The query DESCRIBE my_table; should return column names from mysql -
One way to do that is to use javascript / jQuery to kick off an Ajax event when the div contents change. I don't have sample code but I posted similar code for a sortable list recently. In my example when the list order changes jQuery sends an Ajax request to the server and a php script updates the database.
-
Network Solutions (and almost every other hosting provider) support htaccess. You can maintain it through their control panel or by uploading your own .htaccess file to a directory, just don't mix the two methods because changes made in one won't be reflected in the other. http://www.networksolutions.com/support/does-network-solutions-support-htaccess-files/
-
Why not just use htaccess and put all of the restricted materials into a protected directory? http://httpd.apache.org/docs/2.2/howto/htaccess.html
-
trying to identify categories from products in a url
davidannis replied to 1internet's topic in PHP Coding Help
I think it is possible to determine. Let me try to explain my example again: Category Table: id Parent id Cat name 1 cars 2 1 sports 3 1 luxury 4 2 ferari Products prodid cat prod name 1 4 ferari 2 4 deluxe ferari now, you ca get 4 kinds of urls: 1. site.com/cars/sports/ferari // cat with name same as product 2. site.com/cars/sports/ferari/ferari //prod with name same as cat 3. site.com/cars/sports // cat name unique 4. site.com/cars/sports/ferari/deluxe ferari //prod name unique You look up the last part of the url by prod name in case 3 you get no results for prod "sports" so you know the url ends in a category Once you find the product record you look at the category column. In case 1 you see cat id is 4 - read the category table and you see that the next level up is not ferari - so you are in the category ferari In case 2 you see cat id is 4 - read the category table and the Cat name column == the name of cat 4 - so it is the ferari product in case 4 you see cat id is 4 - read the category table and the Cat name column == the name of cat 4 - so it is the deluxe ferari product -
I think that should work. Did you try it?
-
trying to identify categories from products in a url
davidannis replied to 1internet's topic in PHP Coding Help
Either make all the products conform to a pattern: site.com/category/p-productname site.com/category/sub-category/p-name1 site.com/category/sub-category/sub-sub-category or if you have a name that is ambiguous keep going up levels until you disambiguate: So if you start with: site.com/category/sub-category/product1 = site.com/cars/sports/ferrari and ferrari is in both the product and category table, go up a level and see if the product ferrari is in the sports category - if it is great - if not you are in the subcategory ferrari. -
I may not have graduated from medical school like she did, but now my wife's got nothing on me.
-
You can override the css for this site in your browser and make it anything you want. Instructions are here.
-
Long ago I started with a php function that generated an html select list from a mysql table. Over time, I've needed versions that did various things differently (two fields displayed between the <option> and </option> or a div displayed based on the selected value) so I've kept building new versions. Every time I build a new version I think "boy I should make a class and extend it to do things the new way" but I never have and now I must have half a dozen versions of the code. Today I sat down and started coding my class and quickly realized that I need to actually figure out what I put in the parent class and where I draw the line and create another class based on the first. Mostly I code procedural and I could really use some help thinking this through. Here's what I have in terms of permutations that I want to accomplish: Build an SQL select set a where clause set an order by select multiple columns to concatenate as labels (for example: <option citycode='$cid'>$city, $state, $country</option> ) Build html Allow list to start with value ='' (eg <option value=''>Choose a state</option> <option value='AK'>Alaska...) set a selected= value (or values for multiples) <div> s No <div> display Display of a <div> if other is selected input type=text textarea Display of a <div> for each value seected Types Select list single or multiple Radio checkboxes So, do I create a class with methods for each type of html list and a child class for the divs? A parent with the divs and children where I override the method that created the html for radio and checkboxes, something else entirely? Thanks, David
-
For independent probabilities you just multiply 0.33 X 0.33. Think of a coin. What are the chances of 3 heads. Make a table of all outcomes (called a truth table) HHH HHT HTH THH TTH THT HTT TTT We see one of the 8 outcomes is HHH (1/2 X 1/2 X1/2) = 1/8 But you don't need both outcomes to be one or five, just one, so make the truth table and count the instances of at least one one or five.
-
Could you have some whitespace characters, perhaps spaces or tabs in the data? Try using trim http://php.net/manual/en/function.trim.php
-
The more that I look at this the harder it gets. The problem I see with curl, my original idea (sorry), is that it returns the response to the server, not the browser. There is a project on sourceforge called snoopy that might be able to do it (I've seen a few hints at it but don't know enough to be sure). Another alternative would be to intercept the submit with Javascript, add the fields you want via Ajax and then POST the data to the merchant website.
-
Why not submit the form to your own script that then uses curl to load the merchant page, including your special variables in the request?
-
So, after the include print_r($_POST) shows a value in $_POST['username'] but you can not echo it with? $username = $_POST['username']; echo $username; FWIW: you should salt (add some unique per user characters) the password and use a more up to date function than md5. Anyone else have any ideas on the inability to echo the username?
-
I just cut and pasted your code, commented out the two includes, added a print_r($_POST) ran it on my local machine and I get the expected results: Array ( [username] => davidannis [password] => test ) davidannisThere is no such user with the entered username try print_r($_POST); before and after the includes.
-
if you comment out the includes does it still not echo?
-
"transforming" a table list to a comma-separeted list instead?
davidannis replied to xwishmasterx's topic in PHP Coding Help
I think that if you use Psycho's code the list is in the variable $field1List then just $field1Values = array(); while($row = mysql_fetch_assoc($result)) { $field1Values[] = $row['field1']; } $field1List = implode(', ', $field1Values); fwrite ($fh, $field1List); -
Barand, I've been thinking about your solution and I think that it would also require rewriting the jQuery code to not use the sortable / serialize methodology. Here's why: jQuery's serialize gives us an array of id's sorted by order in the list. So, if we start with a list of id's 0 through 10 in order and we move #9 to #3 we get back an array in $_POST['listitems'] that looks like this (0=>0, 1=>1, 2=>2, 3=>9, 4=>3, 5=>4, 6=>5, 7=>6, 8=>7 9 =>8, 10=>10) Now in my script to process the results I have no way to know that 9 was moved to 3 short of going through the entire array. The resulting array I received is indistinguishable from a starting array of (0=>0, 1=>1, 2=>2, 3=>9, 4=>4, 5=>3, 6=>5, 7=>6, 8=>7 9 =>8, 10=>10) where id=3 was moved up one notch for example.
-
Thank you Barand. That is an elegant way to make the code more efficient.
-
I have implemented the function using jquery but I understand the desire to do it server side, both as a learning exercise and because I've heard that it is good to provide an alternative to those who are not willing/able to run javascript. FWIW here is the code I used in my project: <script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <script type='text/javascript'>//<![CDATA[ $(document).ready(function(e) { $("#sortable").sortable({ 'containment': 'parent', 'opacity': 0.6, update: function(event, ui) { var info = $(this).sortable("serialize"); $.ajax({ type: 'GET', url: 'process_sort_competitors.php', async: false, data: info, success: function(data) { alert(data); } }); } }); }); //]]> </script> server side: $table_name='competitors'; foreach ($_GET['listItem'] as $position => $item) { $position= mysqli_real_escape_string($link, $position); $item=mysqli_real_escape_string($link, $item); $query = "UPDATE `$table_name` SET `print_order` = $position WHERE `competitor_id` = $item AND `company_id`='".$_SESSION['company_id']."'"; $result=(mysqli_query($link, $query)); //if (!$result) $message .= "$item not updated.\n.$query\n" ; else $message.="$item is now in position $position\n"; if (!$result) $message .= "$item not updated.\n" ; else $message.="$item is now in position $position\n"; } echo 'Competitor Print Order Updated'."\n".$message; I can provide a link to the working code if you want it.
-
PHP read from csv file. Handle a couple of columns differently.
davidannis replied to zwlanham's topic in PHP Coding Help
Looks like the code that you have commented out did what your asking and you replaced it. Why? -
Is it possible that App.php exits before it gets to the include ('config.php')? Can you post some of the code from App.php?