Jump to content

rvdb86

Members
  • Posts

    142
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rvdb86's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey guys, I am trying to perform a very simple select query from a MySql database, but for some reason the array that is returned contains duplicates. This is my code: $allData = mysql_query("SELECT * FROM table"); while($result = mysql_fetch_array($allData)){ echo "<pre>"; print_r($result); echo "</pre>"; } and my output looks like this: Array ( [0] => 62 [id] => 62 [1] => 502fa610b7856 [intID] => 502fa610b7856 [2] => 4c36fd909b37208b [location] => 4c36fd909b37208b [3] => obj2 [shoe] => obj2 [4] => how_to_use_with_back_displayed [action] => how_to_use_with_back_displayed [5] => 2012-08-18 17:26:22 [date] => 2012-08-18 17:26:22 [6] => 00:00:00 [duration] => 00:00:00 ) Why is it duplicating every column?? TIA!
  2. Hey Barand, Thanks again for helping me! Using your suggestions I managed to come up with a solution, I dont think it is the most elegant coding around but I thought I would post it to help future readings of this post: $result = array_reverse($months); foreach ($result as $name) { $numDate = date('Ym', strtotime($name)); $monthlyXPs[$numDate] = 0; } while($line = mysql_fetch_array($timelineData)){ foreach ($monthlyXPs as $key => $value) { if($key == $element){ $monthlyXPs[$key] = $element; } } } Thanks Again!
  3. Hi Guys, I am trying to build a statistics system that shows the amount of interactions per month. Each interaction is saved in a databas with the date. I have pulled the data from the database and counted it using sql: Code: $timelineData = mysql_query("SELECT COUNT(date), EXTRACT(YEAR_MONTH FROM date) AS xpdate FROM table GROUP BY MONTH(date)"); Output: Array ( [0] => 2 [COUNT(date)] => 2 [1] => 201206 [xpdate] => 201206 ) Array ( [0] => 85 [COUNT(date)] => 85 [1] => 201207 [xpdate] => 201207 ) As you can see from the output, I have 2 interactions in June and 85 in July. So far so good... I have a timeline that shows the last 7 months. Per month I want to show the amount of interactions. Code: $months = array(); for ($i = 0; $i < 7; $i++) { $timestamp = mktime(0, 0, 0, date('n') - $i, 1); $months[date('n', $timestamp)] = date('M', $timestamp); } $result = array_reverse($months); foreach ($result as $name) { $numDate = date('Ym', strtotime($name)); //$monthlyXPs = '0'; while($line = mysql_fetch_array($timelineData)){ echo "<pre>"; print_r($line); echo "</pre>"; if ($line['xpdate'] == $numDate){ //echo "<li>".$line[0]."</li>"; $monthlyXPs[$numDate] = $line[0]; } else { //echo "<li>0</li>"; $monthlyXPs[$numDate] = '0'; } } } What I am attempting in the code above is, firstly to loop through the months, then to compare the month against the results of the database. If the month appears in the array, assign $monthlyXPs with the value of the number of Interactions. If the month does not appear, assign the value 0. It doesn't seem to be working , my output looks like this: Array ( [201201] => 0 ) Any suggestions, help, corrections will be really appreciated! TIA!
  4. Thanks for everyones help! ignace your solution solved the problem! But never the less thanks to everyone for taking the time to reply and help out
  5. Hey Barand, Thanks for helping me. I have tried this earlier, and as you can see from the output below it does not seem to work: Code: if($line['action'] != "wow_displayed"){ echo $line['action']; echo "<br />"; } Output: wow_displayed [b]lower_device[/b] raise_device videoplaceholder lower_device switchToObject1 (to get the output I changed the if statement to != when it was set to == nothing was outputted.)
  6. Sorry, I post the worng code (I was playing around trying different things to try get it working). Also == doesnt work
  7. Hey guys, I feel like a complete NOOB I just dont understand why the if statement that I am trying to use isn't working and I would really appreciate some help! I am looping through an array, and when one of the elements matches a string I would like to output something: Here is my code: while($line = mysql_fetch_array($result)){ if($line['action'] != "wow_displayed"){ echo "WE HAVE IT! - ".$line['action']; echo "<br />"; } } I really don't understand what I am doing wrong TIA for any help or suggestions!
  8. thanks for the offer i'm alright. I know that it is possible to spoof the email address, but this is exactly what I was trying not to do. If you were to spoof my email address and send me an email it is 99% likely to end up in the spam folder and if you send porn that way it is 99.9999999999[you get the point]% likely to end up in spam. That is why i was trying to achieve the same affect as sending through SMTP from php script to make is as unlikely as possible to make sure the email does not get marked as spam.
  9. Hi, I hope this is at all possible... one of my clients wants to send their visitors and email after they complete one of the forms on their website. The problem is that the email account they want to use to send the email from is a microsoft exhange email account. The network manager informed me that I cannot access the email throught SMTP (as i usually would do) but they only offer HTTP access. How would I be able to send the visitors an email through php and make it send from this email account? I would really appreciate suggestions! TIA!
  10. I have made a bit more progress but still need help! I am trying to create a script that checks that the posted values from a form, exist in an array. This is simple if the user has to fill out all the fields, but they don't so I need to check the $_POST array to see which variables exist, and then check each variable in the array of results from the DB. Heres my code so far: $SearchResult = array(); foreach ($apartmentsList as $key1 => $apartment){ foreach($_POST as $key2 => $p){ if($_POST[$key2] === $apartment[$key2] && $_POST[$key2] != "advancedSearch"){ $SearchResult[$apartment["Id"]][$key2] = $_POST[$key2]; } } } $sfields = count($_POST); // FOR TESTING PURPOSE, COUNT HOW MANY POSTED VARIABLES $results = count($SearchResult); // FOR TESTING PURPOSE, COUNT HOW MANY MATCHES THERE ARE IN ARRAY echo "<h4>totral sFields = ". $sfields. "</h4>"; // FOR TESTING PURPOSE echo "<pre>".print_r($_POST)."</pre>"; // FOR TESTING PURPOSE echo "<h4>totral Results = ". $results. "</h4>"; // FOR TESTING PURPOSE echo "<pre>".print_r($SearchResult)."</pre>"; // FOR TESTING PURPOSE //****** THIS PART DOESN'T CHECK THAT ALL POSTED VARIBALES MATCH if (in_array($_POST, $SearchResult)){ // PRINT MATCHES echo "<hr><h2>Search Results</h2>"; echo "<pre>"; print_r($SearchResult); echo "</pre>"; } This code manages creates the array $SearchResult that holds the results where at least one posted variable matches the array. How do I ensure that ALL posted variables are in the array? Thanks in advanced, any suggestions are really welcome
  11. I would really appreciate help with this search function i am trying to make; I have a search form and an array of products from a database to compare against each other. I have made the first step which checks the form data against the array if all the form fields are filled out: // IF ALL SEARCH FIELDS ENTERED if ($_POST["apType"] != "0" && $_POST["apArea"] != "0" && $_POST["numGuests"] != "0" && $_POST["numBathrooms"] != "0" && count($_POST["appliance"]) > 0 && count($_POST["amenities"]) > 0 && count($_POST["business"]) > 0){ if ($apartment["TypeId"] == $_POST["apType"] && $apartment["Area"] == $_POST["apArea"] && $apartment["Guests"] == $_POST["numGuests"] && $apartment["Bathrooms"] == $_POST["numBathrooms"]){ //Check if appliances selected are in the apartment array $ApE = 0; foreach ($_POST["appliance"] as $ap){ if(in_array($ap , $apartment["Appliances"])){ // If they are in the array increase ApE $ApE++; } } //Check if amenities selected are in the apartment array $AmE = 0; foreach ($_POST["amenities"] as $am){ if(in_array($am , $apartment["Amenities"])){ // If they are in the array increase AmE $AmE++; } } //Check if business selected are in the apartment array $BuE = 0; foreach ($_POST["business"] as $bu){ if(in_array($am , $apartment["Business"])){ // If they are in the array increase BuE $BuE++; } } if ($ApE > 0 && $AmE > 0 && $BuE > 0){ // IF ALL CRITERIA MATCHES PRINT INFO echo $apartment["Address"]."<br />"; } } } The thing is that this only works if the user completes the whole form, but ideally the script needs to check which fields were filled in and do the corresponding checks against the array. Anyone know how I can improve the above script do to this? TIA!
  12. Hey keith, I guess you are probably sick of seeing this thread but I was hoping you have some spare time to help me out on one more thing. I am trying to create a search function for the apartments base on all their elements, type, area, appliances etc. So far I have created the form (the easy part) but I dont really know where to start with searching the joined tables. I thought maybe to make use of the IN clause but I have never used it before and not sure this is the correct way, I also tried creating a multidimensional array of all the apartments and compare the values posted from the form against the array, but again I don't know if this is the best way. Here is my form: <fieldset> <label for="apType">Apartment Type: </label> <select name="apType" id="apType"> <option value="0"> </option> <option value="7">Studio</option> <option value="8">One bedroom</option> <option value="9">Two bedroom</option> </select> <br /> <label for="apArea">Apartment Location: </label> <select name="apArea" id="apArea"> <option value="0"> </option> <option value="4">Upper West Side (west 70th and west 71st Street)</option> <option value="5">Upper East Side (east 80th and east 81st street)</option> <option value="6">Midtown West (west 47th street)</option> </select> <br /> <label for="numGuests">Number of Guests: </label> <select name="numGuests" id="numGuests"> <option value="0"> </option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> <br /> <label for="numBathrooms">Number of Bathrooms: </label> <select name="numBathrooms" id="numBathrooms"> <option value="0"> </option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <br /> Amenities: <input type="checkbox" value="1" name="amenities[]" id="Air Conditioning"><label for="Air Conditioning">Air Conditioning</label> <input type="checkbox" value="2" name="amenities[]" id="Telephone"><label for="Telephone">Telephone</label> <br /> Appliances: <input type="checkbox" value="1" name="appliance[]" id="Microwave"><label for="Microwave">Microwave</label> <input type="checkbox" value="2" name="appliance[]" id="Stove"><label for="Stove">Stove</label> <input type="checkbox" value="3" name="appliance[]" id="Full Refrigerator"><label for="Full Refrigerator">Full Refrigerator</label> <input type="checkbox" value="4" name="appliance[]" id="Iron"><label for="Iron">Iron</label> <input type="checkbox" value="5" name="appliance[]" id="Ironing Board"><label for="Ironing Board">Ironing Board</label> <br /> Business Tools: <input type="checkbox" value="1" name="business[]" id="WIFI"><label for="WIFI">WIFI</label> <input type="submit" name="advancedSearch" value="Search" /> </fieldset> I hope I am not asking to much, I just have not been able to find any examples/tutorials or answer for this type of structure. Thanks in advanced for any suggestions you can offer!
  13. Hi, I am trying to make a search function, and I am not 100% sure how to match the posted values from the search form to the array. I should mention that idea is to search a database of apartments based on different aspects of each apartment, such as their type, the area they are in, appliances that are included in the apartment etc. The form has a few options, but none of them are mandatory. The form fields are: Type: Select, Name: Type Type: Select, Name: Area Type: Check boxes, Name: Appliances Type: Check boxes, Name: Amenities here is an example of the array of an apartment: [apartmentId] => 27 [Area] => 6 [Appliances] => Array ( [0] => 1 [1] => 5 ) [Amenities] => Array ( [0] => 1 [1] => 2 ) [TypeId] => 9 The values of the array are the id's for each item, so in the array example above the area Id is 6 and it has the amenities with the id's 1 and 2 I need a way to check if elements match only if they have been inputed in the form, and a way to loop through the arrays and print only the apartments that match the posted variables submitted from the search form. Thanks for any suggestions or just taking the time to read this!
  14. its quite simple actually, put the function or at the top of the page, or in an external file and include it into the page, and then all you have to do is change your sql querys to applly the function to the variables you are inserting into the db. heres an example: $sql1="UPDATE $tbl_name SET status='safehtml($status[$i])',... WHERE id='$id[$i]'"; $result1=mysql_query($sql1);
  15. This usually happens becuase you have a error in you sql query and the error gets printed before you use the header() function. Like farkewie suggested, check line 7, and it may be worthwhile to check you sql query
×
×
  • 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.