Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. btw, doing $row = mysql_fetch_array($result, MYSQL_ASSOC); is the exact same as doing $row = mysql_fetch_assoc($result);
  2. echo "<a href=\"delete.php?id={$row['ID']}\" onclick = \"return confirm('Are you sure');\">DELETE</a>";
  3. Don't know but I first got into PHP a little over 4 years ago and it was there at least that long ago.
  4. Oh okay I didn't read that far back, sorry.
  5. okay && is the same as AND and || is the same as OR. The only difference between them is the order in which PHP will parse them mathematically. Kind of like how division will always be performed before multiplication, then addition, then subtraction. && will take precedence over AND and || will take precedence over OR so if you used both of && and AND in the same condition, && will be evaluated first.
  6. pseudo-code login.php <?php session_start(); // code to check username / password here if (username and password are correct) { $_SESSION['loggedin'] = true; } ?> somepage.php <?php session_start(); if ($_SESSION['loggedin']) { // user is logged in, do something } else { // they are not logged in, do something } ?>
  7. exactly. ($var == 2 AND $var == 3) would break down because $var cannot equal two things at the same time. Now if you were to do this: $var = 5; if(($var > 4) AND ($var < 6)) { // condition is true, code here will execute } elseif (($var > 4) OR ($var < 6)) { // condition is true, but will not get executed because the first condition was true } But you could do this: $var = 10; if(($var > 4) AND ($var < 6)) { // condition is not true, code here won't execute } elseif (($var > 4) OR ($var < 6)) { // condition is true, code will execute }
  8. Not really, unless you are storing previously inputted data somehow like in a cookie or flatfile or database, in which case, the only way to be accurate about it is by uniquely identifying to user (making them login, storing a cookie, etc..). And even then, it would be a mix of clientside and server side script, as php doesn't do the whole dynamic dropdown thing. You'd have to use css and/or js for that part. Hell, I'm not sure js can even do that. That sort of thing is built into the browser itself, having been made in a "real" language like c++, java, or whatever the browser was made with.
  9. I don't really think one thing or another. It's just data being passed. Go for it.
  10. In essence, an array is just a list of variables. The name of the array is like the title of your list. For example, let's make a list of fruit: Now you can make an individual variable for each fruit like so: $Apples = "apple"; $Oranges = "orange"; $Bananas = "banana"; $Grapes = "grape"; $Watermelon = "watermelon"; But that's not very convenient coding-wise, because chances are, you're going to want to do something with those variables. Since they have no connection except for in your own head (your own understanding of them), you're going to have to do the same thing individually to them. For instance, if you wanted to echo out your fruit, you would have to do this: echo $Apples; echo $Oranges; echo $Bananas; echo $Grapes; echo $Watermelon; That's not very efficient. It would be better to just make a loop, but you can't do that with individual variables. That's one of the powers of arrays. You can loop through your items with an array. The array could look like this: $fruit = array("apple","orange","banana","grape","watermelon"); Another way to write that would be: $fruit[] = "apple"; $fruit[] = "orange"; $fruit[] = "banana"; $fruit[] = "grape"; $fruit[] = "watermelon"; Each time you assign something to $fruit[] it adds it to a new row in the list. That row is called an element. You can specify what row like this: $fruit[0] = "apple"; $fruit[1] = "orange"; $fruit[2] = "banana"; $fruit[3] = "grape"; $fruit[4] = "watermelon"; You don't even have to go in order, and you don't even have to use numbers. Using words instead of numbers to specify the row is called making an associative array. This is useful for code readability. For instance if you have an account somewhere, your account information might be stored in an array like this: $account['firstname'] = "John"; $account['lastname'] = "Doe"; $account['password'] = "123abc"; And that is the same thing as writing it like this: $account = array("firstname" => "John", "lastname" => "Doe", "password" => "123abc"); Each row's "name" or "label" or "identifier" (be it a word or number) is called an array key, and the data it points to is called the value key => value. The key goes between the [] braces. Earlier when we did $fruit[] = "..." for each fruit, we did not specify a key. If you do not specify a key, php will automatically assign one. If there is no previous key for $fruit, it starts at 0, and each time you assign something new, it takes the previous key and adds 1 to it. Like I said earlier, one of the main advantages to arrays is being able to loop through the information. Earlier I showed you how if you had individual variables, you would have to echo them out individually, but with your fruit in an array, you can simply do this: foreach($fruit as $key => $val) { echo "$key $val <br />"; } Since the array keys are numbers in our $fruit array, we can use a for or while loop just the same, though we would first have to find out how many fruits are on the list. We can do this by counting them like so: $count = count($fruit); for($x = 0; $x < $count; $x++) { echo $fruit[$x] . "<br />"; } That loop will go through every element of the $fruit array and echo out the value until it reaches the last element. One other difference between a foreach loop and the other loops is that you can utilize the key as well as the value. You cannot do this with the other loops without adding other array functions that will tell you the keys. The foreach loop allows you to do that automatically by specifying the "..as $key => $val" in the loop's argument. The foreach loop is mostly useful for dealing with arrays where the keys are words (associative arrays) like with the $account array example I gave, or where numbered keys are not in a traditionally countable order (like if the keys were like 0, 20, 15, 42, 88, 37 ... ) On that note, another advantage of arrays is that you can sort them. Going back to our fruit array: $fruit[] = "apple"; $fruit[] = "orange"; $fruit[] = "banana"; $fruit[] = "grape"; $fruit[] = "watermelon"; or $fruit = array("apple","orange","banana","grape","watermelon"); Let's say we want to echo them out like before, but we want to echo them in alphabetical order. PHP comes with several sorting functions and methods for sorting things based on different specifications like standard alphabetical, reverse alphabetical; there is even a way to make custom specifications, like say for instance you want to sort by how many letters in each fruit there is. But let's just do a standard alphabetical sort: $fruit = array("apple","orange","banana","grape","watermelon"); $fruit = sort($fruit); foreach($fruit as $value) { echo "$value <br />"; } That will output: And you can also nest arrays inside arrays. Instead of making the value of an element a single piece of data, we would just start another array inside it. This is called multi dimensional array. You can mix and match and nest another array inside even that, making it a 3d array, the sky's the limit! But I won't really get into all that, as I think I've been more than long winded about this already.
  11. example: <?php // foreach loop foreach ($_POST['names'] as $key => $val) { echo "$key $val <br />"; } // echo individually echo $_POST['names'][0]; // echo "junk" echo $_POST['names'][1]; // echo "trunk" ?> <br /> <form method = 'post' action = ''> <!-- the select name needs to be an array --> <select name="names[]" multiple="multiple"> <option value="junk">Junk</option> <option value="trunk">Trunk</option> </select> <br /><input type = 'submit' value = 'submit'> </form>
  12. You said you wanted only 3 but I don't see anywhere in your code where you actually do that. You can add that to your query. Also, I'm not really seeing why you are wanting to send several unique variables to flash when they all seem to be containing the same type of data. I would suggest making one string with the values delimitated with a pipe (|) or comma (,) or something and have AS explode it when it gets it. getimages.php <?php require_once ('????.php'); //Connect to database RESET TO SAFE PATH ONCE IT FUNCTIONS // you ordered by rand() now limit it to just 3 $query = "SELECT images FROM movie_images ORDER BY RAND() LIMIT 3"; $result = mysql_query($query) or die(mysql_error()); // You were using _fetch_array with the _num argument, which // is the exact same as using _fetch_row, so just use it while ($row = mysql_fetch_row($result)) { // make an array of the images $info[] = $row[0]; } // make a | delimitated string to pass to flash $images = implode($info,"|"); // pass it to flash echo "&images=$images"; ?> Then in flash, the code would look something like this: var imagelist = new Array(); var recvars = new LoadVars(); recvars.onLoad = function(success){ if(success){ imagelist = this.images.split("|"); } } recvars.load("getimages.php");
  13. that's not php that's html or css.
  14. I'm not 100% but I think that's something you have to set up with specific carriers.
  15. Well he was supposed to do that because it's a 2d array. It's a 2d array with only 1 position for the first dimension.
  16. mysqli_query($update_db, $mysqli_connect) you had the arguments reversed
  17. Umm, where did he do that? It didn't work because the way array_unique works is it removes duplicates inside a single level array, but the values were inside separate arrays (which is inside a master array).
  18. Yes you can use whatever email address you want. I mean, all email addresses are "web" addresses... What I am talking about is the cellphone sends the message to [email protected] and you would use php to access and read it and do whatever. I don't really know the specifics or have any specific code for that, as I didn't look that far into it at the time. I was just bored one day and made some little form for sending the msg to the phone and I sent a reply back to my [email protected] address. I never got as far as parsing the email with php or nothin' though.
  19. lol wow... a company can't afford 20 bucks for some software? fail.
  20. I don't really know what all a gateway offers you but I do know you can text back and forth between a cell phone and a plain old php script on a plain old server. All you need is the cell phone's sms address. You can google and find a list of the major companies' addresses like for instance a tmobile cell phone address would be like [email protected]
  21. Hey now, I use ftp, just because that's what's built into html-kit. Not that I ever do anything important...
  22. Depends on your host as to how to setup a cron job, or if you're even allowed to. I suggest you talk to them about that. But if you have cpanel there is an icon for setting up a cron job (again, assuming your hosting plan allows cron jobs). Follow the instructions. As far as the script you want the cron job to run every x amount of time, it can be something as simple as <?php $conn = mysql_connect('localhost','dbusername','dbpass'); $db = mysql_select_db('dbname',$conn); mysql_query("delete from table where date_end > now()", $conn); ?>
  23. well, you kind of can. There are certain things you can do through things like java applets and activeX. Also I know several of the "online" virus scanners actually have you download a small program that acts like a client separate from a browser. And also, if you really wanted to go all out, you could always make your own browser via c++ etc.. and not impose such restrictions on it. Or change FF yourself, I mean, it IS open source...
  24. $result = mysql_query("selet user_id from tbl_user_upload where user_id = '$userName'"; if (mysql_num_rows($result) > 0) { mysql_query("UPDATE `tbl_user_upload` SET count = count + 1 WHERE user_id = '$userName'"); } else { mysql_query("INSERT INTO `tbl_user_upload` (user_id) VALUES ('$userName')"); } This is a very bad way to actually do this because it's ugly and doesn't handle errors or anything like that, but hopefully you can use this to get the idea.
  25. post some actual code please.
×
×
  • 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.