Jonathon
Members-
Posts
1064 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Jonathon
-
Regex Query
Jonathon replied to Jonathon's topic in PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
Right, this is the solution I came up with, just thought i'd put down the solution I came up with rather than leaving it. <?php DEFINE ('DB_USER', ''); DEFINE ('DB_PASSWORD', ''); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'test'); $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); mysqli_set_charset($dbc, 'utf8'); // determine what the page number should be or default to page 1 $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; // fetch the info to be paged from DB function fetch_results($page, $perPage){ // make $dbc available to function global $dbc; // where to start and how many results per page $start = (int)($page - 1) * $perPage; $perPage = (int)$perPage; // query for results $q = "SELECT `result` FROM `results` LIMIT {$start}, {$perPage}"; $r = mysqli_query($dbc, $q); // put results into avriable to be returned while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $result[] = $row['result']; } return $result; } function fetch_total_results(){ // make $dbc available global $dbc; // create query for number of pages needed $q = "SELECT COUNT(`result`) FROM `results`"; $r = mysqli_query($dbc, $q); // put results into variable $totalResult = mysqli_fetch_array($r, MYSQLI_NUM); // return the number of records in DB $totalResults = $totalResult[0]; return $totalResults; } // iterate through results on that page foreach (fetch_results($page, 2) as $data){ echo "<p>{$data}</p>"; } $path = $_SERVER['PHP_SELF']; $path = substr($path, 0, -4); // determine number of pages $totalPages = ceil(fetch_total_results() / 2); for($i = 1; $i <=$totalPages; ++$i) { echo " <a href=\"{$path}/{$i}\">{$i}</a> "; } ?> And this .htaccess file <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^test$ test.php RewriteRule ^test/([0-9])?$ test.php?page=$1 </IfModule> Things to work on are just outputting 'Next and 'Previous' tags along with not allowing the current page to be a link. Also i'm going to try and automatically remove any trailing slashes. -
Hi Larry & all, I was just working through your PDF chapters on the extra material on PHP5 advanced and I am having a problem, I keep getting this error: "A PDFlib exception occurred: Handle parameter or option of type 'image' has bad value 0" This is using both mine and your code from the download section and i've used my own image and also your image with the same result. I was wondering if you know what this exactly means? I've done a fair amount of Googling, but sadly the I can't seem to see what the problem even means. I also kept finding reference to a DOMPDF in Google, but didn't think this applied to my set up. I'm using XAMPP and PDFLib 7.0.5 There's no rush in replying and I don't necessarily need a massive answer, I just can't even find what a bad value of 0 means?If you happened to know what this could mean, could you let me know please. Also I did see somewhere try an absolute path, which still returned the same answer. Thanks Jonathon
-
No problem :-)
-
I like to post good extensions or apps that aid development/Design, so a new one I found the other day is the https://chrome.google.com/webstore/detail/hehijbfgiekmjfkfjpbkbammjbdenadd IE tab for chrome that lets chrome open a page in IE, you can also pick from IE 7 up to IE 9 for it to be opened with. That's it really.
-
Regex Query
Jonathon replied to Jonathon's topic in PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
Ok thanks Larry, I shall have a blast at this tomorrow :-) -
Regex Query
Jonathon replied to Jonathon's topic in PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
Well yes I agree that that method works. But my intended plan was to just generate a URL of test/4 // To represent page 4 of the results or test/3 // to represent page 3 of the results This is where I started to confuse myself in how to make this happen, because the way I was going about it was wrong. I do need the 's' and 'p' as far as I can see as the whole pagination script runs using these. But I couldn't figure out how to mask them and just display the current page. I shall have another go tomorrow. ** Although it's not tomorrow, I was just thinking if I could pass a 3rd parameter to the URL that would indicate the current page, so text.php?s=2&p=6&c=2 /*Where c was the current page*/ Would that be the way to then remap that query to just display the current page of the results i.e. test/3 -
Regex Query
Jonathon replied to Jonathon's topic in PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
Well that would rewrite to test/2/2 I think. The idea is to just show the page number so test/4 would be page 4 of the results.Appreciate the reply though :-) -
A while ago Larry, you helped me with a .htaccess rule. The full rule was: <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / # Add slashes to the end of everything, if not present: RewriteCond %{REQUEST_URI} !\.[^./]+$ RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://localhost/$1/ [R=301,L] # Redirect about/ and about/X to about.php?get=X: RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^about/$ about.php RewriteRule ^about/([A-Za-z\+\-]+)/?$ about.php?get=$1 </IfModule> This rule basically added a trailing slash to a URL and mapped URLs to www.example.com/page/ rather than page.php I've set myself a little goal, to take a pagination script and use .htaccess to clean it up. so where a url was previously: www.example.com/page.php?s=30&p=4 /* In my example I'm only using a set of 11 results and display 2 results per page just so I had a decent number of pages to test but didnt have to write loads of Data */ it would look like www.example.com/page/4 So I started quite basic with the .htaccess and thought i'd build it up, so my initial code mapped "test" to "test.php" was: (Here i'm not adding trailing slashes to everything by the way) <IfModule mod_rewrite.c> RewriteEngine on #RewriteRule ^test$ test.php #RewriteRule ^test/([0-9\+\-]+)$ test.php?s=$1&p=$2 </IfModule> But I've started to confuse myself now really. If I type: http://localhost/test -> returns Result 1 + Result 2 :-) http://localhost/test/1 -> returns Result 2 + Result 3 :-) http://localhost/test/2 -> returns Result 3 + Result 4 :-) /* You can see where this is going */ Obviously this is wrong, It would suggest to me that my $_GET['s'] is being mapped as the row to start at from what ever number follows the final slash i.e. /2 Which got me thinking how to correct this and also not mess up my links either. So does anyone have any pointers?
-
Coffee Shop Tutorial:Menu Links Not Working
Jonathon replied to swgj19's topic in Effortless E-Commerce with PHP and MySQL
I should add politely that the book does require comfort with PHP at an intermediate level. If you are having problems with relative paths and error messages like that. It may be more worth your while to read "PHP and MySQL" before tackling this book as some parts of it are quite complicated and technical. -
I would think you are much more likely to find your website has been attempted to be hacked rather than your PC/MAC.
-
I didn't think the code stays in the editor itself. Surely it stays in the files/folders that the project is saved too?
-
Debugging: Latest Ie Vs. Firefox
Jonathon replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
These things happen I guess. -
Debugging: Latest Ie Vs. Firefox
Jonathon replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
Don't get me wrong all browsers have their quirks. I haven't got IE 10, I have 9 though for testing. I'm not really sure what i'd class this problem as, it seems to be how it handles the HTML, but why it varies on different OS I don't know. Firstly is this the HTML5 embed tag? If it is shouldn't it have this above the <html> tag? <!DOCTYPE HTML> It may be as simple as that, if you have HTML errors or CSS errors I'd run them through the validators, make sure your running the right spec though, i'e don't run HTML 1.0 transitional through a HTML5 validator etc. http://validator.w3.org/ http://jigsaw.w3.org/css-validator/ Also, FF offers (in my opinion) the best debuging extensions for JS CSS + HTML. And you can get things like the https://addons.mozilla.org/en-US/firefox/addon/web-developer/ which provides you with a massive array of tools to try and counteract these problems, and direct links to validators -
Best Free Text Editor
Jonathon replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
Context is free and is my backup editor, but you can get free IDEs, Netbeans is free (I believe). Also Gedit as an editor I like too. http://netbeans.org/ http://www.contexteditor.org/ http://projects.gnome.org/gedit/ -
Debugging: Latest Ie Vs. Firefox
Jonathon replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
By Latest IE what do you mean? IE9 or BETA 10? But as a personal feeling, IE would be the last browser I'd ever use to debug as FF, Chrome and Opera are better in my opinion. To be honest I didn't know that IE provided any kind of built in debugging? Other than the console that reports various JavaScript errors that often probably shouldn't be errors. (Or at the least, they should be handled more inline with FF Chrome Safari etc. However, that doesn't mean that I don't try and get IE to play ball). However reluctant it is! -
Parse Erro On Script 4.2
Jonathon replied to scottdg's topic in PHP for the Web: Visual QuickStart Guide (4th Edition)
I just copied this code and ran it ok, obviously I just put in fixed values in place of the $_POST. $end is often a case of omitting a ; or } -
Blank Index.Html File
Jonathon replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
I wouldn't say its a bad idea, but I think Larry's point is that with products being writable, people could be snooping through your files as if you just went to www.something.com/products/ it would list all the files. I persoanlly remove the indexing ability of folders that i don't want people to be able to look in even if they aren't writeable. -
Blank Index.Html File
Jonathon replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
Is it because it's the only writable folder then? -
Blank Index.Html File
Jonathon replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
From memory isn't the products page the only one that's not outside the root? I haven't got the book to hand -
Shop.Php Mysqli_Num_Rows() Boolean Given
Jonathon replied to AndrewT's topic in Effortless E-Commerce with PHP and MySQL
Perhaps I should explain clearer - apologies. Glad it's working for you though. -
Ha, indeed