-
Posts
3,584 -
Joined
-
Last visited
-
Days Won
3
Everything posted by JonnoTheDev
-
By moving the directory outside of the website document root i.e # document root public_html # includes directory public_html/includes to # document root public_html # includes directory includes You can still include files from the includes directory in your scripts using the correct path however there is no access publically i.e http://www.xyz.com/includes
-
Simple - use URL parameters. The paremeter is used in the WHERE condition after it has been validated: http://www.xyz.com/page.php?param=abc http://www.xyz.com/page.php?param=def <?php // page.php $result = mysql_query("SELECT * FROM table WHERE field='".mysql_real_escape_string($_GET['param'])."'"); ?>
-
Look at PHPs simpleXML extension. You can parse the XML document.
-
Bad method - file_get_contents() is slow If you want to check that the webpage exists then I would check the HTTP header. i.e if you get no header the site maybe dead. You may also get a 404 header for an invalid url. <?php // return header function httpHeader($url) { $urlParts = parse_url($url); $fp = @fsockopen($urlParts['host'],80,$errno,$errstr,20); $out = "GET ".$url." HTTP/1.1\r\n"; $out.= "Host: ".$urlParts['host']."\r\n"; $out.= "Connection: Close\r\n\r\n"; @fwrite($fp,$out); $content = @fgets($fp); return $content; } print httpHeader("http://google.com")."\n"; ?>
-
This may take some processing becase of the number of queries needed. I suggest displaying all letters even if there a 0 rows. I would then display 0 results found after a search. However here is how you would do the initial question: <?php $range = range('a','z'); for($x = 0; $x < count($range); $x++) { $result = mysql_query("SELECT id FROM table WHERE topics_name LIKE '".$range[$x]."%'"); // destroy letter if no results found if(!mysql_num_rows($result)) { unset($range[$x]); } } // now loop your letters out foreach($range as $letter) { print $letter."<br />"; } ?>
-
You may need to optimise your mysql configuration for the number of users (my.cnf). More memory in your server will also help. Are your tables properly optimised i.e. indexes setup correctly. Also setup a slow query log so you can see the offending queries. http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html
-
Yes, your database structure should be designed to store the values of the user input i.e the answer chosen. This should be recorded after each submitted question to restore a previous session. You do not save objects to a database.
-
[SOLVED] How to Repopulate Form Fields
JonnoTheDev replied to thesaleboat's topic in PHP Coding Help
The above code is not needed at all. 2 simple facts 1. If you are editing data from the database then the field will be prefilled with the database value 2. If the user resubmits the data and there is a form error you want the value of the $_POST array to remain in the field value rather than the database value. The initial shorthand if statement does just this -
$query = "SELECT * FROM vehicles LIMIT 10";
-
In the UK? I need help to find a PHP Linux webhost.
JonnoTheDev replied to fishfinger's topic in Linux
We use these guys. Have both shared and dedicated servers. http://bpweb.net/ -
You should use a session. You do not save an object to a database.
-
[SOLVED] How to Repopulate Form Fields
JonnoTheDev replied to thesaleboat's topic in PHP Coding Help
Not quite. You may want the post value there if there are form errors <input type="text" name="hire_date" id="hire_date" value="<?php echo isset($_POST['hire_date']) ? $_POST['hire_date'] : $rows['hire_date'];?>" size="34" maxlength="50" /> -
How to send data from one server to another server
JonnoTheDev replied to ravemanhattan's topic in Javascript Help
Wasn't aware of that thanks. However the Ajax call could initiate a server side script to post to a remote server. -
AJAX/JS/PHP/MySQL works in Firefox but not in IE.
JonnoTheDev replied to max_power's topic in Javascript Help
Javascript Sorry I haven't the time to install and test your code. If it is possible to post the current URL I could test. -
AJAX/JS/PHP/MySQL works in Firefox but not in IE.
JonnoTheDev replied to max_power's topic in Javascript Help
I use IE 8. The alert suggests you have an Ajax object. Your functions must be using unsupported methods. I would carefully debug your functions to check that the correct data is available within. -
AJAX/JS/PHP/MySQL works in Firefox but not in IE.
JonnoTheDev replied to max_power's topic in Javascript Help
Can you add an alert to check the http object exists alert(http) You haven't got javascript disabled have you? -
I don't think that a timeout is your issue. There is no such thing that is why you cannot find any information. If you get a blank page then the script must be terminating with an error but you haven't set your php configuration to display errors. Add these lines to the top of the script preferably in a common include to all pages: ini_set('display_errors', 1); ini_set('error_reporting', E_ALL & ~E_NOTICE);
-
Singelton/ Loading configuration file once
JonnoTheDev replied to nadavgg's topic in PHP Coding Help
http://www.phplibrairies.com/tutorial_design-pattern_en.html -
Google has an API for this http://code.google.com/apis/ajaxsearch/
-
How to send data from one server to another server
JonnoTheDev replied to ravemanhattan's topic in Javascript Help
Yes you can do this. If you wanted to process the form data on another server then the form action parameter would simply point at the page i.e. <form action="http://www.xyz.com/process.php" method="post"> However if you want to do it with ajax then I suggest the accepted method on the remote server is GET so: // Ajax method req.open("GET", http://www.xyz.com/process.php?var1="+val1+"&var2="+val2); With this method you can also store the data on both servers with a second ajax request whereas using the using the form action parameter will send a user to the remote server. You would have to redirect them back. -
AJAX/JS/PHP/MySQL works in Firefox but not in IE.
JonnoTheDev replied to max_power's topic in Javascript Help
This will catch any error function getHTTPObject() { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript alert("XMLHttpRequest not supported"); return null; }; Create the http object within the JS function function requestInfo(url,id,redirectPage) { var http = getHTTPObject(); } -
impossible with a single query. build an array using your programming logic
-
Its difficult for me to picture what you want the result set to look like. I'm guessing pk parent 1 0 2 1 3 1 4 0 5 4 6 4 7 0 8 7
-
Do you not have an authors table? You would achieve this in the following mannor: SELECT a.author, COUNT(f.id) AS totalPosts FROM forum f LEFT JOIN authors a ON (a.authorId=f.authorId) WHERE f.threadId='123' GROUP BY a.authorId ORDER BY totalPosts DESC
-
Not really. All depends on what you need to do with the results. Do you need to keep all results from all sites for reporting? If not why not after your spider has completed one site export and compress the database and then truncate it for the next.