Jump to content

AdRock

Members
  • Posts

    913
  • Joined

  • Last visited

Everything posted by AdRock

  1. That is exacltly what I was trying to do but how do i get it so it goes through a loop a set number of times and pick a random town? I put it in a for loop of 120 and I got over 3000 results where i only need 120 random towns
  2. you need to put something like $files = $_FILES["file"]["name"] ; Just after the file has uploaded. You are passsing an empty variable to the database
  3. I have a huge array of towns with their counties and I want to pick a town at random and display both the town name and the county they belong in I am having trouble picking a random array element. This is a small part of my array $towns = array( 'Bedfordshire'=>'Bedford', 'Bedfordshire'=>'Luton', 'Bedfordshire'=>'Dunstable', 'Bedfordshire'=>'Leighton Buzzard', 'Bedfordshire'=>'Biggleswade', 'Bedfordshire'=>'Sandy', 'Berkshire'=>'Reading', 'Berkshire'=>'Bracknell' ,'Maidenhead' , 'Berkshire'=>'Newbury' , 'Berkshire'=>'Windsor' , 'Berkshire'=>'Wokingham' , 'Berkshire'=>'Abingdon', 'Buckinghamshire'=>'Aylesbury' , 'Buckinghamshire'=>'Milton Keynes', 'Buckinghamshire'=>'Slough' , 'Buckinghamshire'=>'Buckingham', 'Buckinghamshire'=>'High Wycombe', 'Cambridgeshire'=>'Cambridge', 'Cambridgeshire'=>'Wisbech', 'Cambridgeshire'=>'Ely', 'Cambridgeshire'=>'March', 'Cambridgeshire'=>'Whittlesey', 'Cambridgeshire'=>'Chatteris', 'Cambridgeshire'=>'Linton' ); What i want to do is pick 120 random towns with their counties out of a possible 248 towns for($i=0; $i < 120; $i++) { $rand_town = array_rand($towns, 248); echo $rand_town."<br>"; } I've checked the array size and it says its 40 which could be the number of counties in the array. Anyway how can i make sure it picksany of the towns that belongs to a county?
  4. I am trying to make myself a dummy data generator to populate my database but i'm having trouble getting a random name out of the array. I am trying to create a 150 long list of random names from the array but all i get is a list of numbers which i presume are the key to each element. What I want is to data Any ideas how i can fix this? $firstnames = array("0" =>"JACK", "1" =>"OLIVER", "2" =>"THOMAS", "3" =>"HARRY", "4" =>"JOSHUA"); for($i=0; $i < 150; $i++) { $rand_firstname = array_rand($firstnames,1); $rand_firstname = ucwords($rand_firstname); print_r($rand_firstname); }
  5. That is exactly how I do it. I just put the filename in the database and echo the filename inside the path to the file. Thtat way you don't have to worry about the path becuase that could change
  6. Bu the class id 1 does exist so it would return a result (only for that id)
  7. You need to show your queries etc and possible table structures
  8. I've read this a few times and I am completely lost. What you are trying to do is probably so simple but i don't get what you're saying Try this and tell me what happens SELECT s.name FROM staff s JOIN classes c ON s.id = c.staff WHERE c.staff IN (1,3,10) GROUP BY c.staff
  9. Would help to see what your query look like already
  10. This is part of a function that i got to resize a thumbnail $twidth = "100"; // Maximum Width For Thumbnail Images $theight = "75"; // Maximum Height For Thumbnail Images $lwidth = "400"; // Maximum Width For Thumbnail Images $lheight = "300"; // Maximum Height For Thumbnail Images $picture = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { $imagename = $_FILES['imagefile']['name']; $source = $_FILES['imagefile']['tmp_name']; $target = "./users/".$_SESSION['username']."/albums/".$album."/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "./users/".$_SESSION['username']."/albums/".$album."/full/" . $newname; //This is the new file you saving $file = "./users/".$_SESSION['username']."/albums/".$album."/" . $imagepath; //This is the original file $image = imagecreatefromjpeg($file) ; $currwidth = imagesx($image); // Current Image Width $currheight = imagesy($image); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $lwidth / $currheight; // Length Ratio For Width $newheight = $lheight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $lwidth / $currwidth; // Length Ratio For Height $newwidth = $lwidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $tn = imagecreatetruecolor($newwidth, $newheight) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight) ; imagejpeg($tn, $save, 100) ; imagedestroy($image); $save = "./users/".$_SESSION['username']."/albums/".$album."/thumbs/" . $newname; //This is the new file you saving $file = "./users/".$_SESSION['username']."/albums/".$album."/" . $imagepath; //This is the original file $image = imagecreatefromjpeg($file) ;
  11. I think you may be getting a problem with the field "desc" I had the same problem with that as DESC is a resevered word. Try changing it to description
  12. I think you may have forgotten the () after numrows numrows() I bet it is a method in your database class
  13. This should be the last question. Is there a way i can loop through each of these without having to do loads of if statements? if(!empty($_POST['experience0'])) $experience0 = check_input(implode(",",$_POST['experience0'])); if(!empty($_POST['experience1'])) $experience1 = check_input(implode(",",$_POST['experience1'])); if(!empty($_POST['experience2'])) $experience2 = check_input(implode(",",$_POST['experience2'])); if(!empty($_POST['experience3'])) $experience3 = check_input(implode(",",$_POST['experience3'])); if(!empty($_POST['experience4'])) $experience4 = check_input(implode(",",$_POST['experience4'])); if(!empty($_POST['experience5'])) $experience5 = check_input(implode(",",$_POST['experience5'])); if(!empty($_POST['experience6'])) $experience6 = check_input(implode(",",$_POST['experience6'])); if(!empty($_POST['experience7'])) $experience7 = check_input(implode(",",$_POST['experience7'])); if(!empty($_POST['experience8'])) $experience8 = check_input(implode(",",$_POST['experience8'])); if(!empty($_POST['experience9'])) $experience9 = check_input(implode(",",$_POST['experience9'])); I though about using variable variables but i can't get it to work in a for loop
  14. I've been trying different things and i got the checkboxes to implode with a comma but i'm having trouble with every text field. It still tries to implode the empty fields and i'm getting an error. for each row of text fields //variables for checking the user's name $userid = $_SESSION['userid']; $quals = check_input(implode(",",$_POST['quals'])); $roles = check_input(implode(",",$_POST['roles'])); $region = check_input(implode(",",$_POST['region'])); $experience0 = check_input(implode(",",$_POST['experience0'])); $experience1 = check_input(implode(",",$_POST['experience1'])); $experience2 = check_input(implode(",",$_POST['experience2'])); $experience3 = check_input(implode(",",$_POST['experience3'])); $experience4 = check_input(implode(",",$_POST['experience4'])); $experience5 = check_input(implode(",",$_POST['experience5'])); $experience6 = check_input(implode(",",$_POST['experience6'])); $experience7 = check_input(implode(",",$_POST['experience7'])); $experience8 = check_input(implode(",",$_POST['experience8'])); $experience9 = check_input(implode(",",$_POST['experience9'])); I was thinking about checking if they are empty before doing the implode but is there an effieicent way of doing it like if a for loop?
  15. That's what I thought I've done that with the checkboxes and I created 10 fields for the last part (10 rows on the form) and i using the implode/explode to get each row in it's own field. Just another quick question, the first 2 columns are dates and the other 2 are text. Can you do form validation suing something like: <li> <input name="Experience4[] From" type="text" size="3" maxlength="4" /> - <input name="Experience4[] To" type="text" size="3" maxlength="4" /> <input class="exprol" name="Experience4[] Role" type="text" size="18" /> <input class="expfest" name="Experience4[] Festival" type="text" size="30" /> </li> check_input($_POST['experience4 From'])
  16. Looks yo me like you're checking if $where isn't empty and do the query but what if $where is empty? There is no query to start if(!empty($where)) { $query .= 'SELECT * FROM Homes WHERE '.$where; } else { $query .= 'SELECT * FROM Homes }
  17. I have a form with a lot of fields but they are in groups with checkboxes and text fields. The question is what is the best way to store this data in the database? Would i store the whole $_POST array as a single field and explode when i want to pull from the database or is it best to have a separate field for each value (that would make the table huge with possibly a lot of empty fields)? The one that bothers me the most of the text fields beucase there is 4 text boxes for one row on my form and I have about 10 rows. The form is like an application form where you put in your work experience Here is part of my example form checkboxes <div class="left"> <p class="label_checkbox_pair"> <input type="checkbox" name="quals[]" value="carpenter" /><label for="carpenter">Carpenter:</label> </p> <p class="label_checkbox_pair"> <input type="checkbox" name="quals[]" value="mechanic" /><label for="mechanic">Mechanic</label> </p> <p class="label_checkbox_pair"> <input type="checkbox" name="quals[]" value="electrician" /><label for="electrician">Electrician</label> </p> <p class="label_checkbox_pair"> <input type="checkbox" name="quals[]" value="plumber" /><label for="plumber">Plumber</label> </p> <p class="label_checkbox_pair"> <input type="checkbox" name="quals[]" value="fire warden" /><label for="fire_warden">Fire Warden</label> </p> </div> and text fields <li> <input name="Experience0 From" type="text" size="3" maxlength="4" /> - <input name="Experience0 To" type="text" size="3" maxlength="4" /> <input class="exprol" name="Experience0 Role" type="text" size="18" /> <input class="expfest" name="Experience0 Festival" type="text" size="30" /> </li> <li> <input name="Experience1 From" type="text" size="3" maxlength="4" /> - <input name="Experience1 To" type="text" size="3" maxlength="4" /> <input class="exprol" name="Experience1 Role" type="text" size="18" /> <input class="expfest" name="Experience1 Festival" type="text" size="30" /> </li> <li> <input name="Experience2 From" type="text" size="3" maxlength="4" /> - <input name="Experience2 To" type="text" size="3" maxlength="4" /> <input class="exprol" name="Experience2 Role" type="text" size="18" /> <input class="expfest" name="Experience2 Festival" type="text" size="30" /> </li>
  18. I wouldn't worry about it becuase it's commented out. What version of PHP are you using? I'm using php5 and i don't see that anywhere.
  19. Here is a tutorial which may help you http://www.plus2net.com/php_tutorial/php_form_validation.php
  20. If you're using a form to diplay the checkboxes, why aren't you using a submit button so when you get the $_POST from the button, you can unset all the files by the $_POST['Del'] if(isset($_POST['submit'])) { foreach($_POST['Del'] as $del) { //code to unset the files } } Haven't tested it but the thoery is there
  21. You could do a select in brackets as a field select field1, field2, field3, (select field1 from table2) as field 4 from table1
  22. try changing $sql="delete from assigned_games where id=".$_GET['did']; to $sql="delete from assigned_games where id='".$_GET['did']."'";
  23. Many thanks It works and saves so much code
  24. Is it possible to get all column names and values into an associative array from a mysql query. The reason i ask is that i don't want to have to write $var = $row['var'] $var2 = $row'[var2'] $var3 = $row['var3'] $var4 = $row'[var4'] for every field in the database. i would rather be able to have an array where i just use the element such as echo $array[0];
×
×
  • 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.