-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
The problem is, since the if statement for the login and for the register are both on the same page, and are not linked in any way, they will always both run. Your best bet would probably be to change that registers if statement to an else if, and make it part of the login if block.
-
[SOLVED] Get all duplicate entries in array function.
mikesta707 replied to mikesta707's topic in Javascript Help
nvm fixed it. If curious, it was very simple function getDuplicates(arr){ var r = new Array(); var keys = new Array(); one:for (var i = 0; i < arr.length; i++){ for (var x = i + 1; x < arr.length; x++){ if (arrayEqual(arr[x], arr[i])){ keys.push(x); keys.push(i); } } } for (var y = 0; y < keys.length; y++){ r[y] = arr[keys[y]]; } return r; } just had to push both of the equal keys, instead of only 1 of them! Oh and if anyone is interested in the PHP print_r functions javascript equivalent, Its: function print_r(theObj){ if(theObj.constructor == Array || theObj.constructor == Object){ document.write("<ul>") for(var p in theObj){ if(theObj[p].constructor == Array|| theObj[p].constructor == Object){ document.write("<li>["+p+"] => "+typeof(theObj)+"</li>"); document.write("<ul>") print_r(theObj[p]); document.write("</ul>") } else { document.write("<li>["+p+"] => "+theObj[p]+"</li>"); } } document.write("</ul>") } } Taken from: http://www.brandnewbox.co.uk/articles/details/a_print_r_equivalent_for_javascript/ -
Ok, I have a function, which I want to take all the entries that are duplicates in an array, and store them in another array. Right now It somewhat works, but not how I want it to. I want it to add every entry of the array (IE if there are 6 entries of two, it adds all 6 entries into the new array) Right now it only adds 1 entry that is duplicated. Here is the function as it stands function getDuplicates(arr){ var r = new Array(); var keys = new Array(); one:for (var i = 0; i < arr.length; i++){ for (var x = i + 1; x < arr.length; x++){ if (arrayEqual(arr[x], arr[i])){ keys.push(i) } } } for (var y = 0; y < keys.length; y++){ r[y] = arr[keys[y]]; } return r; } Note: This function is specific for 2 dimensional arrays. I need it this way. Here is my test array: * [0] => object + [0] => taco + [1] => pig + [2] => crap + [3] => nonsense * [1] => object + [0] => dtaco + [1] => dpig + [2] => dcrap + [3] => dnonsense * [2] => object + [0] => taco + [1] => pig + [2] => crap + [3] => nonsense * [3] => object + [0] => dtaco + [1] => dpig + [2] => dcrap + [3] => dnonsense * [4] => object + [0] => adtaco + [1] => adspig + [2] => adcrap + [3] => nadonsense As you can see, I want the new array to have 4 entries, basically the first 4 entries of my original test array (since 0 and 2, as well as 1 and 3 are both duplicates of each other). Right now, when I run the function, and do a print_r on it I get the following: * [0] => object + [0] => taco + [1] => pig + [2] => crap + [3] => nonsense * [1] => object + [0] => dtaco + [1] => dpig + [2] => dcrap + [3] => dnonsense This result isn't terrible, as its kind of doing what I want, but I need it to add every entry that is a duplicate, not just one representative of the duplicates, if that makes sense. Anybody see where I am going wrong? BTW the arrayEqual function I could post, but it is not the problem (Well, I doubt it is, I have tested it quite thoroughly and it seems to work). EDIT: sorry the arrays don't seem to like the way I copy pasted them... I hope you can read it
-
I use the PHP mail function http://us.php.net/manual/en/function.mail.php what I do is take an MD5 hash of their username (but you could really use anything, their password, email address, etc.) and send store this "authentification" hash on the DB. Then I send them a link to a verification page, and set a get variable to their specific hash (a typical link in an email would look like: mysite.com/verify.php?hash=ahdf8a9fh39ahfe8h) then, compare the get variable to the DB, and on whatever row the hash matches, verify the account. make sure that you don't verify twice tho
-
Organizing and structuring content with PHP
mikesta707 replied to ultrasound0000's topic in PHP Coding Help
with pure PHP, the only way to pass data from page to page is with cookies, sessions, and post/get variables. if you dont want to use get variables, I would suggest you use sessions, but beyond that you will probably have to find a non-php solution. i guess you could use cookies, but I dont know how useful cookies would be for this -
[SOLVED] php/mysql and function not process correctly no errors
mikesta707 replied to acctman's topic in PHP Coding Help
trying printing the id variable to make sure it is populated with data. If the SQL syntax is fine, and everything else is fine this is the only thing I could see being wrong. also I am not sure but are you sure you want to use the $id variable and not the $user variable. just a wild guess on my part -
that would only work if you were to submit that to itself, and not on refresh. How exactly does your recalculation work? what makes your page refresh? try posting some code? also I you have to surround indexes of associative arrays with single quotes so the above code should be <td> <input type="checkbox" name="array[]" id="checkboxid" multiple="multiple" value="VALUE" <?php if (isset ($_POST['array']) && in_array ("VALUE", $_POST['array'])) echo ' checked="checked"'; ?> /> <label for="checkboxid">VALUE</label> </td> Idk if that makes a different though
-
jesus christ that wall of text just landed a critical strike for over 9000 damage On a serious note though, it seems you are using Dreamweaver. Im not even entirely sure what your problem is, but im not reading through that tangled mess. Next time try wrapping your code in code tags. if you are having a problem with your div tags its probably an HTML/CSS problem, not a php problem so I think its safe to say this is the wrong forum
-
there are probably examples on the website. However, this is not PHP, but rather is javascript. here is a page with some tutorials on jquery http://docs.jquery.com/Tutorials
-
[SOLVED] php/mysql and function not process correctly no errors
mikesta707 replied to acctman's topic in PHP Coding Help
try putting or die(mysql_error()); after all your queries and see what happens -
well, you close your table tags inside the loop itself... and you have a bunch of different <tr> tags inside the loop, as well as 2 extra curly brackets that I have no idea where they came from. And another echo of a <td> tag that I can't really see a use for. You are going to have to try implementing my code that I wrote in a much different way because as it stands right now, I have no clue what you are doing inside that while loop. its a mess
-
$count = 0; echo "<table><tr>"; while($row = mysql_fetch_assoc($query)){ $username = $row['username']; $stackname = $row['name']; echo "<td>" echo $username; echo $password; echo "<td>" if (($count % == 0){ echo "</tr><tr>"; } $count++; } that should work. I didn't test it though, so it might be a little off syntactically
-
javascript... ahh, beat me too it.
-
you have to iterate through the array. while($row = mysql_fetch_assoc($query)){ $username = $row['username']; $stackname = $row['name']; echo $username; echo "<br />"; echo $password; }
-
having a string with an error message in it, and checking if that has data populated in it is not the best way to go about error handling IMO. I don't really even see where you check if that variable has data in it (unless you didn't post that part) The class variable IS accessible to the rest of the class, and you don't NEED to call an error handling function, but your class would be a lot cleaner imo if it were to have a centralized error handling function. You could avoid writing duplicate code a bunch of time just to make sure there is no data in your objects error variable, and you could avoid having to clear that variable of data everytime you do something new. line 13 looks perfectly fine to me tho... What exactly is the error message you get.
-
array_unique() is leaving empty values in array...
mikesta707 replied to Fog Juice's topic in PHP Coding Help
Array unique preserves the keys of the array, (as it says on the php.net documentation) so that probably has something do to with the empty values. But I don't use array_unique to often so beyond that i don't really know -
again, the get variable is a string, not a boolean value, so you will need to surround the value with quotation marks if (isset($_GET['Splash']) && $_GET['Splash'] != "FALSE") also, since it is a string you are comparing, the comparison operator will try to match the string exactly, so False, and faLse will make that if statement false. if you want to be able to compare any combination of upper and lower case letters to the string "FALSE" use the strtoupper function, and thigns like "false" "False" "falSe" etc. will be turned into FALSE and the if statement will run true. so if (isset($_GET['Splash']) && strtoupper($_GET['Splash']) != "FALSE")
-
I believe that static pages are more search engine friendly (Don't quote me on that, Im not SEO expert) but regardless of how you serve the static pages (whether its via javascript, like my example, or PHP) they are still static pages so web crawlers (in theory) will still index those pages, thus using javascript vs. php won't really cause any detrimental effects as far as your ranking in a search engine goes. Besides, as long as you site has a site map and all those other search engine friendly tricks then you should be fine. But again, I'm not SEO expert, so you may want to consult someone in the SEO forums on this topic (I think there is a SEO section on these forums EDIT: yes there is =) )
-
well, I guess you could use javascript, and use the onChange event to dynamically change the action of the form, and you could also have the submit button go to a certain page based on the value of the form. But that is javascript and not really PHP. If you wanted to do it with pure PHP you would probably have to have a page that gets the value of the form, and then redirects the user to the specific page, but that option is kind of... well... slow and pointless since there are much faster ways of doing what you want. I would go with javascript, something like <html> <head></head> <body> <form name="myForm" action="" method="post"> <select name="product" id="product"> <option value="/product1.html">Product 1</option> <option value="product2.html">Product 2</option> <option value="product3.html">Product 3</option> </select> <input type="button" name="submit" value="Go!" onClick='window.location.href=document.getElementById("product").value/> </form> </body> </html> I didn't test that though, so the syntax may be slightly off. But thats the basic Idea of how I would go about it
-
well firstly, since your checkEmail function doesn't return anything, you won't ever see an error. If you want to check if the email passed or failed, you want to return true or false, and based on the output an error in the checkEmail function, (Or, as I like to do, create an error function for handling errors, and call that function with an error message) Also, you cannot concatenate stuff onto the error1 string because it doesn't have any value stored into it. (You do this in your valEmail and valBlanks check. You may also want to do a trim on the input value just to make sure it isn't a bunch of spaces. What line is line 13?
-
adding 24 hours to current time and saving it to mysql database
mikesta707 replied to debuitls's topic in PHP Coding Help
try echoing your timestamp1 variable. Also, what datatype is your SQL column? -
just wrap what you want to echo in the foreach with the div tags? assuming you want to wrap whats inside the following code block in a div tag //show results echo "<h2>Results</h2>\n"; echo '<p>Files on Disk</p><ul>'; if(!empty($arr_hdd_files)) { foreach($arr_hdd_files as $k => $v) { echo "<li>$v</li>"; } echo '</ul>'; } else { echo '<li>None</li></ul>'; } echo '<p>Files in Database</p><ul>'; if(!empty($arr_db_files)) { foreach($arr_db_files as $k => $v) { echo "<li>$v</li>"; } echo '</ul>'; } else { echo '<li>None</li></ul>'; } echo '<p>Files inserted to DB</p><ul>'; if(!empty($arr_insert_files)) { foreach($arr_insert_files as $k => $v) { echo "<li>$v</li>"; } echo '</ul>'; } else { echo '<li>None</li></ul>'; } ?> just echo div tags around them... echo "<div id='something'>"; //show results echo "<h2>Results</h2>\n"; echo '<p>Files on Disk</p><ul>'; if(!empty($arr_hdd_files)) { foreach($arr_hdd_files as $k => $v) { echo "<li>$v</li>"; } echo '</ul>'; } else { echo '<li>None</li></ul>'; } echo '<p>Files in Database</p><ul>'; if(!empty($arr_db_files)) { foreach($arr_db_files as $k => $v) { echo "<li>$v</li>"; } echo '</ul>'; } else { echo '<li>None</li></ul>'; } echo '<p>Files inserted to DB</p><ul>'; if(!empty($arr_insert_files)) { foreach($arr_insert_files as $k => $v) { echo "<li>$v</li>"; } echo '</ul>'; } else { echo '<li>None</li></ul>'; } echo "</div>"; ?>
-
[SOLVED] Invalid argument supplied for foreach()
mikesta707 replied to sawade's topic in PHP Coding Help
I'm not sure how your specific mail method is set up, but the standard PHP mail function takes the $headers argument as the 4th parameter I think. Here is how it should be set up bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) but your mail function seems different. From what I can tell from your errors, your header variable should be an array. try making each line an entry in the array IE instead of $headers = "MIME-Version: 1.0\n" . "From: contactus@medsolutionservices.com\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; try $headers = array("MIME-Version: 1.0\n", "From: contactus@medsolutionservices.com\n", "Content-Type: multipart/mixed;\n", " boundary=\"{$mime_boundary}\""); -
Preform Action when you scroll over a specific Part of a page
mikesta707 replied to mikesta707's topic in Javascript Help
Hmm, that more or less works, but unless the mouse is in a specific area (an admittedly large-ish area), my function won't be called. is there a way to do it based on the scroll bar position? or is onmouseover my best bet. It does "work" but not with the functionality I intended. Regardless, thank you!