Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Ok, well at least we're getting to the bottom of this slowly! Its working in IE7 for me. What happens in IE for you? Does it just not update, or do you get a blankpage? Edit: Only thing i can find about IE7 and ajax issues is that they added native support for XMLHTTP. If you go to tools->internet options->advanced you should find a checkbox which should be ticked called something like 'native support for XMLHTTP' (it's near the bottom). However, from what i've read, it should work using an activeX object even with that off.
  2. It appears to be working perfectly for me, updating too. The 22:08 entry just came on screen. Edit: In Firefox and IE
  3. Well it looks like there's an issue with the call to the shell_exec() function, since email-delayed.php doesn't display anything. Im afraid im not too hot on that sort of thing, so perhaps someone else could suggest why it's not working. I assume it's not something stupid like a mistyped path?
  4. No problem, and you to. If you're done here, can you mark this as solved?
  5. Well, show as your new code! I've still not learnt the art of mind reading...
  6. No, it should all be left as "log" - its just the id of the span tag, which is needed to allow its inner HTML to be updated. Not entirely sure why its stopped working. When i visit the link you gave, no content appears to be being retrieved. I notice you've changed the page we make a request to, to email-delayed.php. I assume this still contains the same thing as ajax.php? And im unsure as to why the newlines are not being preserved. The pre tags should keep them. p.s. When you post code, can you put it inside of tags (without the spaces)
  7. Haha, yeah - the initial call is made by the javascript function called in the body onLoad attribute. Have a read up over on www.ajaxfreaks.com/tutorials if you're interested. It's where i took the javscript from.
  8. I dont think you were being ignorant. The question was pretty clear. Unfortunately i can't bring you an easy answer. This is why you need to plan your database. You're gonna have to alter the way you store the status of each product. You need to have a number represent the status, which can then by ordered in the normal way. e.g: 1 = Featured 2 = Coming Soon 3 = Regular 4 = Sold You could store the names of each status with their relevant ID in a separate table and join the results if you also want to pull the name. If its really not an option, then AFAIK, your only option is 4 separate queries. You could make one use of the mysql_query() function and UNION the results, but this is still 4 separate mysql queries and hence pretty inefficient. Edit: If there's a limit clause to deal with, then it becomes more complicated. You'd have to perform the separate queries and stick the results in an array, then output only the required results. I'd definitely recommend changing the status to an integer.
  9. Sorry, my fault. Missed off the semi-colon. Try: <?php require_once('db.php'); include('functions.php'); if(isset($_POST['Login'])) { if($_POST['username']!='' && $_POST['password']!='') { //Use the input username and password and check against 'pending' table $sql = 'SELECT ID, Username, Active FROM pending WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['password'])).'"'; $query = mysql_query($sql) or die(mysql_error().'<br />Query:'.$sql); if(mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); if($row['Active'] == 1) { session_start(); $_SESSION['user_id'] = $row['ID']; $_SESSION['logged_in'] = TRUE; header("Location: members.php"); } else { $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link'; } } else { $error = 'Login failed !'; } } else { $error = 'Please use both your username and password to access your account'; } } ?> <?php if(isset($error)){ echo $error;}?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <input type="text" id="username" name="username" size="32" value="" /> <input type="password" id="password" name="password" size="32" value="" /> <input type="submit" name="Login" value="Login" /> </form>
  10. For the real-time update, how about this: <html> <head> <script type="text/javascript"> function createRequestObject() { var req; if(window.XMLHttpRequest){ // Firefox, Safari, Opera... req = new XMLHttpRequest(); } else if(window.ActiveXObject) { // Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else { // There is an error creating the object, // just as an old browser is being used. alert('There was a problem creating the XMLHttpRequest object'); } return req; } // Make the XMLHttpRequest object var http = createRequestObject(); function sendRequest() { // Open PHP script for requests http.open('get', 'ajax.php'); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4 && http.status == 200){ // Text returned FROM PHP script var response = http.responseText; if(response) { // UPDATE ajaxTest content document.getElementById("log").innerHTML = response; setTimeout(update,1000); } } } function update() { sendRequest(); } </script> </head> <body onLoad="sendRequest()" /> <pre> <span id="log" name="log"></span> </pre> </body> </html> Then use this as ajax.php: <?php echo shell_exec('tail -n 50 /var/log/logfile.log'); ?> This will update the page every second without a full page refresh. Alter the time, which is given in milliseconds, in the setTimeout function if you need to.
  11. Try changing your query to these two lines: $sql = 'SELECT ID, Username, Active FROM pending WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['password'])).'"' $query = mysql_query($sql) or die(mysql_error().'<br />Query:'.$sql); And show us the result. I can't see anything immediately wrong with the query.
  12. GingerRobot

    hello

    If that passes for articulate, then i fear for my sanity.
  13. You dont have to separate by slashes/dashes. You could either use the substr() funcion , or rebuild the new string by accessing the characters individually: <?php $num = '12001102'; $length = $num[0].$num[1];// $account_type = substr($num,2,2); echo $length.'<br />';; echo $account_type; ?> That said, separating by shashes would probably be better - what happens if one of thse suddently needs to be 3 digits long. If you separate by shashes, it wouldn't be a problem. Finally, if this data is coming from a database table, you'd be better off storing each piece of information individually. What happens when you suddenly want to see all the items where the account type is 00? If could be done with the way you're storing information at present, but it would be easier if you stored each piece separately.
  14. Sure, no problem: <?php //first the query. In this query, we perform a join. A join is where you join (duh ) information from two tables. We select the id and url from booklinks, along with the title from books. In the where clause, we specify that we dont want any rows where the url is empty, and we also say we want rows where the ids are the same in the two tables(this is where the join occurs) $sql = "SELECT Booklinks.oid,Booklinks.amazonuk,Books.Title FROM Booklinks,Books WHERE Booklinks.amazonuk != '' AND Booklinks.oid=Books.oid"; $result = mysql_query($sql) or die(mysql_error()); $ranks = array();//blank array - otherwise on the first iteration we would be using an undefined array while(list($id,$url,$title) = mysql_fetch_row($result)){//cycle through the results. I've taken to using the list() function in this way if there are only a few rows being retreived. Basically, it assigns the values of the 3 elements of the array returned my mysql_fetch_row to the given variables $page = file_get_contents($url);//extract the information from the the page preg_match('|</b> ([0-9,]+) in|s',$page,$matches);//use a regular expression to find the the numbers $num = intval(str_replace(',','',$matches[1]));//replace the commas with a blank, and evaluate as an interger (we do this to allow the sorting to ocur) if($num != 0){//a ranking exists - we only want to insert if there is a ranking $ranks[$id] = array($title,$num); } } //this is our user defined sort function. We need to use this because we are soring a multidimensional array. The way the usort function works is to pass in two elements from the given array to a user defined function. That function must return a number. If the number is positive, the first element, $a is put first. If its negative, the second $b is first function mysort($a,$b){ return $a[1] - $b[1]; } uasort($ranks,'mysort');//note we actually use uasort. This is exactly the same as usort, with the exception that index associated is maintained. That is, the key of the array remains tied to the data. If we used usort, the array would reassign keys staring with 0, which we dont want, since the key is the id of the book. $n = 1; foreach($ranks as $k=>$v){//cyle through the array to output the results echo '<a href="viewbook.php?id='.$k.'">'.$n.'# '.$v[0].' with rank: '.number_format($v[1])."</a><br />\n";/ $n++; } ?> As for your final question, thats correct. After all, the contents of the page is the source. It is the browser that renders that HTML as the webpage. Hope that helped. If you've still got some questions on how it works, then feel free to ask. As for your final comment about speed, both of the things you mentioned would help this. Though i've not use the Amazon API, i would imagine it would be a quicker method of grabbing what you need, whilst only updating this table every so often would remove the delay on every page load. And i wouldn't worry, we've all got to start somewhere. At least you're wanting to know how it works, not just have a solution.
  15. You are missing a single quote in this line: $sql="INSERT INTO courses ('cid','sid','sub','num','ins') VALUES ('1',".$sid."','".$sub."','".$num."','".$ins."')"; Change it to: $sql="INSERT INTO courses ('cid','sid','sub','num','ins') VALUES ('1','".$sid."','".$sub."','".$num."','".$ins."')"; Edit: You should also place column names inside backticks (if you use anything) not single quotes: $sql="INSERT INTO courses (`cid`,`sid`,`sub`,`num`,`ins`) VALUES ('1','".$sid."','".$sub."','".$num."','".$ins."')"; And for goodness sake, put your code inside the tags! You should also note that $sid appears to be empty.
  16. If the number is definitely the only one contained between two slashes, try: <?php $str = 'user/worstmovieever/video/1957687/someotherparameter/'; preg_match('|/([0-9]+)/|',$str,$matches); $num = $matches[1]; echo $num; ?>
  17. You made a mistake with your or die statement on the 4th line of the above code. Change it from: $result=mysql_query($sql) or die(mysql_error); To: $result=mysql_query($sql) or die(mysql_error());
  18. You could do it with a regular expression: <?php $str = 'user/worstmovieever/video/1957687/someotherparameter/'; preg_match('|[0-9]+|',$str,$matches); $num = $matches[0]; echo $num; ?> Or if the number is always in the same place in the string, you could explode by the slashes: <?php $str = 'user/worstmovieever/video/1957687/someotherparameter/'; $bits = explode('/',$str); $num = $bits[3]; echo $num; ?>
  19. When you say 'it returns a blank' What do you actually mean? Do you recieve a page with nothing on it? If so, i would imagine there is an error somewhere, but you have the setting display_errors off. Try adding these two lines at the top of your script: <?php ini_set('display_errors','On'); error_reporting(E_ALL); ?> And show us the errors. If thats not what you mean, then please expain in some more detail.
  20. I think most would agree that it's more conventional to apply the nl2br function when you retrieve the data from the database, not when you enter it into the database. The function converts new lines to the HTML break line tag, which would only be wanted when the data is output as HTML. So if you wanted to output the data in some other way (like in a text file), then the break lines would be unwanted.
  21. That line exists where? Edit: So i see, its in the original code. I assumed we were now working with rajiv's code?
  22. Well, on this line here: echo "<option value='{$row['uname']}' >{$row['uname']}</option>"; You try to use the row uname, but in your query, you select from username. Since you're no longer getting an SQL error, i would imagine the correct row is username, and so you must change the above line accordingly.
  23. needs to be either $query = mysql_query("SELECT username FROM users WHERE .... "); OR $query = mysql_query("SELECT * FROM users"); Err, no it doesn't. The query is actually executed later in the script with this line: $result=mysql_query($query); However, if John has posted the exact line where he as defined the query, then there are other issues. If the query is just: $query = "SELECT username FROM users ; Then you are missing a double quote. It should be: $query = "SELECT username FROM users" ; However, when you change it to that, we are going to find another error somewhere, since there must be a double quote lying around preventing the syntax error that should be display with the current code. Edit: Perhaps i've confused the issue here. In rajiv's cleaned up code, the query is executed. I assumed the variable $query, was defined elsewhere.
  24. You just need to roundup, rather than round down. If you rerun rajiv's code with January 1st 2008 as the finish date, it will show 0 days, when, of course, it should be 1. By rounding down, you don't count today. <?php $intYear = "2009"; $intTime = strtotime("{$intYear}-01-01"); $intToday = time(); $intDays = ceil(($intTime-$intToday)/86400); print $intDays; ?>
  25. How about actually showing us the error. And the line in question. And while you're at it, wrap your code inside tags (without the spaces)
×
×
  • 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.