PHP - Get Current Array Key Help
$_SESSION[$c] is an array in a loop. How do i do an if statement that gets the current array key?
Code: [Select] if($_SESSION[$c][]==$_SESSION[$c][1]) { } i tried the above but i get this error "Fatal error: Cannot use [] for reading in..." Similar Tutorialsi get this error Warning: current() [function.current]: Passed variable is not an array or object.. for this Code: [Select] $lastblock = current( ${"s".$row} ); print_r($lastblock); when i change to this it works.. Code: [Select] $lastblock = current( $s0 ); print_r($lastblock); The problem is i won't know the $row seeing as it is in a while loop. Solution? Example: i have an array of names array{ => john [1] = ted [2] = jeff } and i display them like this: john, ted, jeff but jeff is currently logged in so i want his name to display first(i have my reasons lol) how would i go about this? i got as far as: if(in_array($user->user_name, $likes)) { $user_key = array_search($user->user_name, $likes); } then hit a brain freeze. Thanks Hi all, Is there a function or method to delete element from current position in array without knowing the index. For example: $ar = array( 1, 2, 3, "test", 4, 5, "test2" ); while( $v = current( $ar ) ) { if( key( $ar ) == "test" ) { // remove element from the array where key equals "test" // i could count every cycle and splice from that index but i wonder can that be done without it // i am looking at the php array functions but i can't find any that will delete from element from current position in array echo 'key( $ar ) je test. key( $ar ): ' . key( $ar ); } next( $ar ); } One thing that i don't understand is that when i run example above the "test" key is found and when i echo it it gives me 0. Hey all.. I'm trying to pick up PHP by reading ebooks and follow tutorials. I am now busy with creating a thumbnailgallery from uploaded pics per user. I want to let the visitor scroll through a row of thumbnails by clicking next or previous. There are 3 different rows of thumbnails. Here's how it looks like: <<previous (row1 of 6thumbnails) next>> <<previous (row2 of 6thumbnails) next>> <<previous (row3..... ) next>> when page loads mysql fetches rows of information for the filenames...then there is a foreach row loop that does first a do ..while loop to build up the thumbnailrows...and then creates the navigation links previous and next who send the "page"+1 or "page"-1 to _GET array so that the thumbnail 7 until 12 will be shown. The problem i run into is that i want the main code page to remember at which "page" of scrolling through the thumnails he is. Now it is that when a user scrolls one row of thumbnails and stops at the 3rd "page" of it and then clicks on a different row to go to "page" 2 of that row that all the rows jump together back to "page" 1. I thought there may be a solution in storing the number of row and the number of page into an array but can't seem to find a solution.... Has anybody got experience in this? Help would be very welcome i'm totally stuck and cant read about it in tutorials/ebooks.... greets from holland.. GJ Hello - I've come to an issue with something I'm working on and have searched around with no luck. When editing user accounts I want it to not be able to change the e-mail address into existing ones on other rows, but when submitting the form it takes into account that this particular rows email address is the same as the one which was sent via $_POST and throws up the error. The desired behaviour I want is for it to ignore the ID of the row which was posted, but take into account every other row. Here's the code as it stands at the moment: $email = $_POST['email']; $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); } if (mysql_num_rows($checkemail) > 0) { return $this->error("The e-mail address you provided is already associated with an account."); } Hi, I'm wanting to find rows whose date is within the next week of the current month of the current year. The format of the date is, for example: 2010-10-28 Any ideas guys? Thanks lots! Hi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin?? echo '<select name="year_of_birth">',"\n"; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { if($i == $thisYear) { $s = ' selected'; } else { $s=''; } echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n"; } echo '</select>',"\n"; Hey all, How can i get the current URL including any $_POST variables which arent visible? Thanks. HI There, I am using this type of code to self load a submitted form <form name = "testform" method = "post" action = "<?=$_SERVER['PHP_SELF']?>" onsubmit = "return check_data()" > Apart from using $_SERVER['PHP_SELF'] is there another way of determining the current URL within a script ? regards, Steven Matthews is this possibe with php? Hello! Once again, I find myself in the need of help regarding PHP. What I have is a URL that looks like this: http://domain.com/gallery/?album=3&gallery=65 What I need is to extract the number that comes after "album=". In this case, it would be the number 3. I currently have this: <?php $url=getPageURL(); $var=explode('album=',$url); $var=explode('?',$var[1]); ?> My problem is that it doesn't result in anything. Can anyone lend a hand? :) It would be much appreciated. Hi, I am trying to write an SQL to XML converter, so so far I have all the records inputted into the db tables, and now I want to append a child, but I don't know how to compare current row's field value with the next row below it, specifically I want to check if a current row is parent of the next row. I have already got the XML to SQL function working (some bugs but for the most part it's working) So for eg: <?php $query=mysql_query("SELECT * FROM edge"); while($row=mysql_fetch_assoc($query) ) { if($row['target'] is parent of the next row), then append the next row as child of current row } ?> Table edge is one of the tables that hold target node/source(aka: parent) nodes. Any help much appreciated! Hi;
I would like to get the current timestamp but the question is that i want to get the real time which is the machine bios time that can't change by the server administrator and not the server time which can be modified to any value.
Thanks
Hi, I have some code that I think worked at one point, but now it doesn't. I have a side navigation menu which I have set as an include. I want to change CSS styling to a current state to whatever page you are current on. For instance the portfolio link would look like this. Code: [Select] <li><a id="current" href="../Portfolio/" title="Visit my Portfolio">Portfolio</a></li> Both the page I am trying to set this on and my includes are in separate directories, so I am not sure if that is messing things up, but the id="current is not being set with what I currently have as my code. Here is my current code. <?php $menu = <<< MENU <div id="SideMenu"> <div id="button"> <img src="../images/NavButton.png" width="184" height="32" class="menu_class" /> <ul class="the_menu"> <li><a href="../index.php" title="take me home">Home</a></li> <li><a href="../Portfolio/" title="Visit my Portfolio">Portfolio</a></li> <li><a href="../blog/" title="See what I have to say">Blog</a></li> <li><a href="../Contact/" title="Get in Touch with me">Contact</a></li> </ul> </div><!--end button div--> </div><!--end SideMenu div--> MENU; $lines = split("\n", $menu); foreach ($lines as $line) { $current = false; preg_match('/href="([^"]+)"/', $line, $url); if (substr($_SERVER["REQUEST_URI"], 0, 5) == substr($url[1], 0, 5)) { $line = str_replace('<a h', '<a id="current" h', $line); } echo $line."\n"; } ?> any ideas? ok guys, i know you guys are awesome and I always get the help and I need some help in figuring the current city and the metropolitan area from an ip address. For example, if I am in Harlem, NY, I need to get the Harlem and New York. I have a code that is partially working but not accurate enough, please guys help, something like groupon will do. Code: [Select] function currentCity () { ( ( (float)phpversion() < 5.3 ) ) ? die ( 'There is something wrong!' ) : ''; $site = file_get_contents( "http://www.google.com/search?q=VBXMCBVFKJSHDKHDKF" ); $getLocationViaGoogle = function ( $html ){ $regex = "#<\w+\s\w+=\"tbos\">([^<]{3,})<\/\w+>#i"; preg_match_all( $regex, $html, $matches ); return $matches[1][0]; }; print $getLocationViaGoogle( $site ); } Hi, when i try to insert to table date value it gives me wrong current date. $joindate = date('m-d-Y'); $sql = mysqli_query($con,"INSERT INTO staff (OracleID,StaffName,Des,joindate,username,password,isadmin) VALUES ('$oracleid','$name','$des','$joindate','$username', '$pass','$isadmin')"); i get this in the main page after making date("d-m-Y",strtotime(date)) 30-11--0001 why is that? Edited April 7, 2020 by ramiwahdanHi, I am trying to build a function that takes in the current primary key as a parameter. My question is how do I extract it/retrieve it and store it in a variable? Any help is much appreciated! Hi all, I want to get the current page name as displayed in the URL, not neccesarily the name of the PHP script that is running. E.g. I have a PHP file 'home.php' that contains iframes that contain other PHP files such as 'frame1.php'. What I want is a script that can be run from frame1.php but that will return 'home.php' as the current page (as displayed in the URL in the browser). How do I do this? Thanks! I'm looking to enter the current time and date into a mysql database using php. My current code looks like this: Code: [Select] $now = date("m/d/y",time()); I then insert $now into the table into a datetime column. This all works but the time when read from the column appears as 0000-00-00 00:00:00. Any ideas what I'm doing wrong? Thanks in advance. I am building a site that needs to update member accounts on a weekly basis. At the moment I have a cron job set for 12:01 am on Monday, that resets five database fields for all of my members. The first field is the current week, the second field is the previous week, the third field is from two weeks ago, the fourth field is from three weeks ago, and the fifth field is from four weeks ago. Obviously the cron job resets the first field to 0, and the data from this field is moved to field two (last week), and so on and so forth, and the data from the fifth field is just removed altogether. However, this is really not preferred, because if/when I get 1000+ users, the cron job will take up a crapload of CPU as many mysql queries need to be executed for each account. So, I am trying to implement a script that checks the last login date for a user, and if they have have not logged in since before the latest Monday, the Monday before that, the Monday before that, or the Monday before that, etc. I have never really worked with dates, so I don't even know how to begin. The last user login is stored as a DATA datatype in a mysql database, and is in the following format: YYYY-MM-DD. Thanks in advance! |