hansford
Members-
Posts
562 -
Joined
-
Last visited
-
Days Won
4
Everything posted by hansford
-
Sorry guys, here's the exact code; function showValue( $id ) { global $arg; --$arg[$id]; extract( $arg ); $element = current( $arg ); extract( $element ); $element = next( $arg ); echo $id . '<br />'; //displays previous elements id; extract( $element ); echo $id . '<br />'; //displays next elements id; }
-
I figured it out by trial and error. Here is what I did. function getValue( $id ) { $element = $arr[$id]; --$arg[$id]; extract( $arg ); $element = current( $arg ); extract( $element ); echo $id; //displays previous elements id; $element = next( $arg ); extract( $element ); return $id; }
-
Given the following example code; if a function were passed the value of $id is there a way to point to the previous or next element in the array to retrieve their values. thanks $arr = array(); for( $i = 0; $i < 10; $i++ ) { $id = mt_rand() + $i; $arr[$id] = "some value"; } function getValue( $id ) { $element = $arr[$id]; //point to previous element or next element beginning from $element position }
-
Not completely understanding what is going on, but if you're submitting a form, using the normal submit process, the page has to reload and cannot be stopped. You could do this with Ajax and the page wouldn't refresh, but instead your client side Javascript would make all the necessary changes after its call to the server.
-
Another good idea is to create a logger function that you can call at various places in your code to see what is getting called, what variables are set to etc. When you call the function in your code it will log whatever you pass to it in a file on the server. Great tool for debugging.
-
Do the images on the website frequently change - if not, then you could do an initial download of the images and then just write a script to get the html. So many website use CSS for image backgrounds that it would seem difficult to write a script for all IMG tags and CSS.
-
Hi people I need a way to loop through an array where $imgid is some random number assigned to each array element and there are 4 fields id, url, tnurl, caption per array element. I need to extract these 4 fields in the same loop iteration. Thanks $_SESSION['imagegallery'][$imgid]['id']; $_SESSION['imagegallery'][$imgid]['url']; $_SESSION['imagegallery'][$imgid]['tnurl']; $_SESSION['imagegallery'][$imgid]['caption']; example: $_SESSION['imagegallery'][347]['id']; $_SESSION['imagegallery'][347]['url']; $_SESSION['imagegallery'][347]['tnurl']; $_SESSION['imagegallery'][347]['caption']; $_SESSION['imagegallery'][892]['id']; $_SESSION['imagegallery'][892]['url']; $_SESSION['imagegallery'][892]['tnurl']; $_SESSION['imagegallery'][892]['caption'];
-
fetch_assoc() returns an associative array, so you need to iterate through the array to get all of the values. while ($row = $result->fetch_assoc()) { printf ("\n", $row["id"], $row["name"],$row["surname"],$row["birthday"],$row["status"],$row["gender"],$row["phone"]); }
-
If whatever value is in $username and $password are not in the database, then you will get "user does not exist" it must match both variables exactly; even a space will make it fail to find a match. edit: removed from post
-
Google is truly your friend. Try this out - I found it by doing a simple search: http://mashable.com/2009/03/30/twitter-badges/
-
$query or $sql...name it whatever, just make sure its consistent in the script. edit: removed from post
-
need some help with a primary school score board
hansford replied to mightymouse's topic in PHP Coding Help
Post your code, please. -
$query= "Select * FROM users WHERE username = '$username' AND password = '$password'"; if(!$result = mysql_query($query)) { //handle error here } else { if(!mysql_num_rows($result)){ echo "user does not exist"; } else { echo "user exists"; } }
-
I tried your suggestion, which should work, but it doesn't. I tried '/cats$/m' also but that didn't work. I tried other modifiers as well, but none of them work on this. I thought this was going to be simple, but it's turned out to be a big research project.
-
Trying to get preg_match to match a word at the end of a line, but keep getting "match not found". Here is the contents of the file and the php code. <html> <head> </head> <body> There are several different varieties of cats </body> </html> $pattern = '/cats$/'; $search = file_get_contents("http://localhost/current/test_file.html"); if($search){ $found = preg_match($pattern, $search, $matches); if($found) echo $matches[0]; else echo "match not found"; } else echo "file not found";
-
I solved the immediate problem. IE does have some issues, but I can't quite pin the documentation of the problem/problems down. I tweaked my code following this example and it worked as far as this issue is concerned. http://www.phpfreaks.com/forums/index.php/topic,115581.0.html The key from the example is all the if/else conditions right down to a complete failure. My original code was similar to this, but I didn't have all the conditions as -why would they be needed-but it seems they are-for IE anyways. If you can't get your code running from this example, then reply and I will post my code as an example. NOTE: the entire code including checking for the ajax object needs to be contained in one function otherwise you will have problems in IE.
-
I would get some more practice and get this working before you leap into ajax -which isn't difficult, but still requires some learning time. Before you echo out your links you should know what $r[] contains. If need be, you query your DB and get all the ID's and store them in an array and then echo out your links with the array. then the link is always what it says it is. If a row gets deleted you need the code in place to get a new array and echo out new links. <a href='viewfull.php?full=' . $r[] . ">view row" . $r[] . "</a>"
-
Heres the js file code function get_page(page) { var httpRequest; if (window.XMLHttpRequest) { httpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { var ieXmlHttpVersions = new Array(); ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.7.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.6.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.5.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.4.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp.3.0"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "MSXML2.XMLHttp"; ieXmlHttpVersions[ieXmlHttpVersions.length] = "Microsoft.XMLHttp"; var i; for (i=0; i < ieXmlHttpVersions.length; i++) { try { httpRequest = new ActiveXObject(ieXmlHttpVersions[i]); } catch (e) { alert(ieXmlHttpVersions[i] + " not supported."); } } } if(document.getElementById('article_no')){ article = document.getElementById('article_no').value; } else{ article = page; } if(typeof(httpRequest) != 'undefined') { var url = 'requestarticle.php?page='; httpRequest.open('GET',url + article, true); httpRequest.send(null); httpRequest.onreadystatechange= function() { if(httpRequest.readyState==4) { var content = httpRequest.responseText; document.getElementById("admin").innerHTML = content; } } } } heres the html file <html> <script language='javascript' src='ajax_request_db.js'></script> <body> <div id='admin'> <table width="400" border="1" align="center"> <tr> <td align="center" colspan="2"><h1>Articles<br/><br/></td> </tr> <tr> <td align="center" colspan="2"><div id='auth'></div></td> </tr> <tr><form action="" method="post" name="adminlogin"> <td align="right">Article number:</td><td><input type='text' id='article_no' size="10" maxlength="6"></td> </tr><tr> <td colspan="2"><input type="button" name='fetch' id='fetch' value="Get Article" onclick="get_page('fetch');"/></td> </tr></form> </table> <p> </p> </div> </body> </html>
-
Do you know why AJAX would fail to respond after the first 2 clicks? The function is called with an onclick event handler inside a button.
-
//make DB connection //delete row $query = "SELECT * FROM 'tablename'"; $result = mysql_query($query); $id_array = array(); while($row = mysql_fetch_array($result)){ $id_array[] = $row['id']; } $count = 1; foreach($id_array as $key){ $query = "UPDATE `xxmembersxx` SET `id` = '$count' WHERE `xxmembersxx`.`id` = '$key'"; mysql_query($query); $count++; }
-
Change the ID's in the database it will save you alot of headache down the road. And then when you have to delete a record make sure that all the other record ID's get updated, so the ID's will never be out of sync
-
We aren't interested in $_GET['full'] if its empty. The error message is for your information only and if it comes up then you know $_GET['full'] is empty ie; hasn't been set. use this instead. echo "An Error has occurred in sending the value of GET[full]";
-
quote]how will I compare the headers[] so I could locate the location?[ are you trying to see what page sent you the information? if so, do a $_POST check for a unique name. You're wanting to store things in an array and keep track of this array after the page is gone. When the page goes so will your array. You need a DB or a session to do this.
-
reigning in my PHP script for completeness and security
hansford replied to RaceCarDriverGuy's topic in PHP Coding Help
I don't understand what you're doing with fputs - are you writing to a text file before validating the form input? I was thinking that you were getting input from a form and you wanted to check if there was actual information entered into that field. please clarify what you are trying to do. -
not following you. please post relevent code and state what page its from