in my code I have a check to see if there is a thumbnail image if not I then resize the image and make a thumbnail. Before running I need to check that I have a big image to crop in the first place.
I do this with
if (!file_exists($thumbnailImg) && file_exists($imgFull))
however the argument file_exists($imgFull) comes back as TRUE even if the folder exists.
one way to get around this problem would be on the command
$imgFull = $pathFull.$img1;
I could check on $img and if it doesn't exist fill it with a value that deliberatly gives an error
if (strlen($img1) > 4){ // counts that $img1 has more than 4 characters ie 1.gif has 5
$imgFull = $pathFull.$img1;}
else
{$imgFull = $pathFull.'error.txt';}
you can check this code working at self catering cornwall .biz
Thursday, 29 May 2008
Tuesday, 27 May 2008
Improving listings for HillsideGlastonbury.co.uk
Hillside Glastonbury.
Earlier this month I did some general maintenance work for Hillside Glastonbury B&b and Self Catering . As well as adding lightview image viewer so to make the viewing of images clearer and easier ( to see the effect check Primrose Cottage and click on the main image) I also added several features in the hope we would get the site a better listing with Google.
The idea was to intergrate the site with Googles applications more - There is a list of Google Business tools at Google Services. On this occasion I have added Google Search of Hillside Glastonbury, Google Map of Hillside, Ashwell Lane, Glastonbury, Somerset, BA6 8BG, Hillside Glastonbury Blog and Google Anayltics for accurate stats on our listing with them.
Earlier this month I did some general maintenance work for Hillside Glastonbury B&b and Self Catering . As well as adding lightview image viewer so to make the viewing of images clearer and easier ( to see the effect check Primrose Cottage and click on the main image) I also added several features in the hope we would get the site a better listing with Google.
The idea was to intergrate the site with Googles applications more - There is a list of Google Business tools at Google Services. On this occasion I have added Google Search of Hillside Glastonbury, Google Map of Hillside, Ashwell Lane, Glastonbury, Somerset, BA6 8BG, Hillside Glastonbury Blog and Google Anayltics for accurate stats on our listing with them.
Friday, 9 May 2008
Oscommerce Adding a dropdown menu selector to catergories.php
This is a small section of a contribution that I am writing to add to the website
www.surfboardsuperstore.co.uk
The site is made with oscommerce. The problem I had was this
///////////////////FORUM///////////////////////////////////////////////////
I'm trying to write a contribution that includes adding extra value to my product tables.
I can get the code to work with an input field - but would ideally like to change this to a dropdown list. The code that is in question is
CODE
surferRecWeight); ?>
so instead of using tep_draw_input_field - i would like to use tep_draw_pull_down_menu. I know that the second arguement for the function tep_draw_pull_down_menu needs to be my array for the drop list. I have tried a couple of different ways to make the array ie
CODE
$ability_array = array('Expert', 'Average', 'Novice');
OR
CODE
$ability_array = array(0 => 'Expert', 1 => 'Average', 2 => 'Novice');
OR
CODE
$ability_array[0] ='Expert';
$ability_array[1] = 'Average';
$ability_array[2] = 'Novice';
either way I get the same result which is that the drop down list only has the first letter of my array element - 'e','a',' & 'n'.
does anyone know why. I know that the function allows strings more than one character ?
the code I am using to call up the function is
CODE
echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('surferRecAbility', $ability_array, $pInfo->surferRecAbility);
///////////////////END OF FORUM ENTRY//////////////////////////////
A very odd problem indeed, To solve this i wrote a hack ( probably very ugly) - after following the trail of the problem here the function that I needed to change was in admin/includes/functions/html_output.php and the function in question was tep_draw_pull_down_menu. so instead of messing this function up, after all every other pull down menu in admin seems to work fine! I created a new one. which is as follows
[code]
function tep_draw_pull_down_menu_two($name, $values, $default = '', $parameters = '', $required = false) {
$field = '
if (tep_not_null($parameters)) $field .= ' ' . $parameters;
$field .= '>';
if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);
for ($i=0, $n=sizeof($values); $i<$n; $i++) {
$field .= ' if ($default == $values[$i]) {
$field .= ' SELECTED';
}
$field .= '>' . $values[$i] . '';
}
$field .= '';
if ($required == true) $field .= TEXT_FIELD_REQUIRED;
return $field;
}
[/code]
the only changes here are in $values[$i]. this is a much simplified version of what was there before, I take it because I created an array without keys etc that this is why it never worked. another solution therefore would be to rewrite the array in a format in keeping with oscommerce. However due to time constraints I will push on with the ugly hack ;)
www.surfboardsuperstore.co.uk
The site is made with oscommerce. The problem I had was this
///////////////////FORUM///////////////////////////////////////////////////
I'm trying to write a contribution that includes adding extra value to my product tables.
I can get the code to work with an input field - but would ideally like to change this to a dropdown list. The code that is in question is
CODE
surferRecWeight); ?>
so instead of using tep_draw_input_field - i would like to use tep_draw_pull_down_menu. I know that the second arguement for the function tep_draw_pull_down_menu needs to be my array for the drop list. I have tried a couple of different ways to make the array ie
CODE
$ability_array = array('Expert', 'Average', 'Novice');
OR
CODE
$ability_array = array(0 => 'Expert', 1 => 'Average', 2 => 'Novice');
OR
CODE
$ability_array[0] ='Expert';
$ability_array[1] = 'Average';
$ability_array[2] = 'Novice';
either way I get the same result which is that the drop down list only has the first letter of my array element - 'e','a',' & 'n'.
does anyone know why. I know that the function allows strings more than one character ?
the code I am using to call up the function is
CODE
echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('surferRecAbility', $ability_array, $pInfo->surferRecAbility);
///////////////////END OF FORUM ENTRY//////////////////////////////
A very odd problem indeed, To solve this i wrote a hack ( probably very ugly) - after following the trail of the problem here the function that I needed to change was in admin/includes/functions/html_output.php and the function in question was tep_draw_pull_down_menu. so instead of messing this function up, after all every other pull down menu in admin seems to work fine! I created a new one. which is as follows
[code]
function tep_draw_pull_down_menu_two($name, $values, $default = '', $parameters = '', $required = false) {
$field = '
if (tep_not_null($parameters)) $field .= ' ' . $parameters;
$field .= '>';
if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);
for ($i=0, $n=sizeof($values); $i<$n; $i++) {
$field .= ' if ($default == $values[$i]) {
$field .= ' SELECTED';
}
$field .= '>' . $values[$i] . '';
}
$field .= '';
if ($required == true) $field .= TEXT_FIELD_REQUIRED;
return $field;
}
[/code]
the only changes here are in $values[$i]. this is a much simplified version of what was there before, I take it because I created an array without keys etc that this is why it never worked. another solution therefore would be to rewrite the array in a format in keeping with oscommerce. However due to time constraints I will push on with the ugly hack ;)
Thursday, 1 May 2008
Making sure that theres no gaps in the filenames of image uploads.
The problem that needed to solved here was that users could upload there own images - and if the filename they were uploading has gaps or whitespace.
It took me a while to get my head around this one, eventhough the solution is fairly simple.
If you have solving the same problem here are a couple of links that may help. Firstly I posted this problem on a developer network forum. you can see that post at http://forums.devnetwork.net/viewtopic.php?f=1&t=82057 .
A tutorial that helps understand how file upload works in php is http://www.tizag.com/phpT/fileupload.php.
Any back to my code.
What I needed to do first was check to check if theres any spaces and replace with '_'
[code]
$img1 = str_replace ( ' ', '_', $img1 );
[/code]
then in move_uploaded_file change it to
[code]
$res = move_uploaded_file($_FILES['img1']['tmp_name'], $abpath .
$img1);
[/code]
staright forward, I have no idea now why I couldn't get my head around this straight away.
It took me a while to get my head around this one, eventhough the solution is fairly simple.
If you have solving the same problem here are a couple of links that may help. Firstly I posted this problem on a developer network forum. you can see that post at http://forums.devnetwork.net/viewtopic.php?f=1&t=82057 .
A tutorial that helps understand how file upload works in php is http://www.tizag.com/phpT/fileupload.php.
Any back to my code.
What I needed to do first was check to check if theres any spaces and replace with '_'
[code]
$img1 = str_replace ( ' ', '_', $img1 );
[/code]
then in move_uploaded_file change it to
[code]
$res = move_uploaded_file($_FILES['img1']['tmp_name'], $abpath .
$img1);
[/code]
staright forward, I have no idea now why I couldn't get my head around this straight away.
Tuesday, 29 April 2008
OSCOMMERCE Hide Categories & Products add on
I was trying to install the contribution for hiding product catergories on a heavily modded Oscommerce store -
this contribution can be found at http://www.oscommerce.com/community/contributions,5907/category,all/search,Hide+Categories+%26+Products
Following the instructions I got everything to work ok except for in the admin area, where we now have a a green and red circle that light up when the folder is active or inactive. After installing the contribution then all buttons would come up red.
the contribution code displaying these items is as follows
[code]
if ($categories['categories_status'] == '1') {
echo tep_image(DIR_WS_IMAGES . 'icon_status_greenl.gif', IMAGE_ICON_STATUS_GREEN, 12, 12) . ' ' . tep_image(DIR_WS_IMAGES . 'icon_status_red_lightl.gif', IMAGE_ICON_STATUS_RED_LIGHT, 12, 12) . '';
} else {
echo '' . tep_image(DIR_WS_IMAGES . 'icon_status_green_lightl.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 12, 12) . '' . ' ' . tep_image(DIR_WS_IMAGES . 'icon_status_redl.gif', IMAGE_ICON_STATUS_RED, 12, 12); }
?>
[/code]
after running test i discovered that the part of the code running this test
$categories['categories_status'] == '1'
was not receiveing any value. So I wrote this hack (albeit ugly and not in the preffered oscommerce format it does work !!)
FIND:
// CATEGORY STATUS
if ($categories['categories_status'] == '1') {
REPLACE WITH
$categories_id = $categories['categories_id'] ;
$selectquery = "SELECT * FROM categories WHERE categories_id = $categories_id ";
$result = mysql_query($selectquery)
or die ("Query failed");
$row = mysql_fetch_array($result);
// CATEGORY STATUS
if ($row['categories_status'] == '1') {
this contribution can be found at http://www.oscommerce.com/community/contributions,5907/category,all/search,Hide+Categories+%26+Products
Following the instructions I got everything to work ok except for in the admin area, where we now have a a green and red circle that light up when the folder is active or inactive. After installing the contribution then all buttons would come up red.
the contribution code displaying these items is as follows
[code]
echo tep_image(DIR_WS_IMAGES . 'icon_status_greenl.gif', IMAGE_ICON_STATUS_GREEN, 12, 12) . ' ' . tep_image(DIR_WS_IMAGES . 'icon_status_red_lightl.gif', IMAGE_ICON_STATUS_RED_LIGHT, 12, 12) . '';
} else {
echo '' . tep_image(DIR_WS_IMAGES . 'icon_status_green_lightl.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 12, 12) . '' . ' ' . tep_image(DIR_WS_IMAGES . 'icon_status_redl.gif', IMAGE_ICON_STATUS_RED, 12, 12); }
?>
[/code]
after running test i discovered that the part of the code running this test
$categories['categories_status'] == '1'
was not receiveing any value. So I wrote this hack (albeit ugly and not in the preffered oscommerce format it does work !!)
FIND:
// CATEGORY STATUS
if ($categories['categories_status'] == '1') {
REPLACE WITH
$categories_id = $categories['categories_id'] ;
$selectquery = "SELECT * FROM categories WHERE categories_id = $categories_id ";
$result = mysql_query($selectquery)
or die ("Query failed");
$row = mysql_fetch_array($result);
// CATEGORY STATUS
if ($row['categories_status'] == '1') {
making sure there's no blank listing on Random search
On the front page of my latest project at www.selfcateringcornwall.biz I have six boxes that advertise properties on the database randomly.
The main work horse of this code is in the mysql query that searches for a listing
[code]
$selectquery = "SELECT * FROM listings ORDER BY RAND() LIMIT 1";
[/code]
li.img1 > 0 AND
what i would like to do is make sure I am not displaying a blank listing - the following statement will check that two values and if they are ok then that row will be included in the random search.
[code]
$selectquery = "SELECT * FROM listings li WHERE li.img1 > 0 AND li.rent > 0 ORDER BY RAND() LIMIT 1";
[/code]
we can also add further filters - for example it may be cool just to list randomly some of the cheapest properties - this next search will only list properties that are under a value of £300
[code]
$selectquery = "SELECT * FROM listings li WHERE li.img1 > 0 AND li.rent > 0 AND li.rent <= 300 ORDER BY RAND() LIMIT 1";
[/code]
The main work horse of this code is in the mysql query that searches for a listing
[code]
$selectquery = "SELECT * FROM listings ORDER BY RAND() LIMIT 1";
[/code]
li.img1 > 0 AND
what i would like to do is make sure I am not displaying a blank listing - the following statement will check that two values and if they are ok then that row will be included in the random search.
[code]
$selectquery = "SELECT * FROM listings li WHERE li.img1 > 0 AND li.rent > 0 ORDER BY RAND() LIMIT 1";
[/code]
we can also add further filters - for example it may be cool just to list randomly some of the cheapest properties - this next search will only list properties that are under a value of £300
[code]
$selectquery = "SELECT * FROM listings li WHERE li.img1 > 0 AND li.rent > 0 AND li.rent <= 300 ORDER BY RAND() LIMIT 1";
[/code]
Thursday, 24 April 2008
Creating Pagination for my search results
Pagination is where in receiving search results you have too many to list on one page. So therefore you would like to have some sort of links system where you can click on '<>' and get the next 10 or however many you wish.
to solve this in my search results I had tried downloading other peoples classes but after some head scratching and figuring out could not adapt them to the search script I had already wrote. In the end I decided it'd be better if I wrote the code myself. Here is how I reached my final aim - I am hoping to write this in such a way that it may help others try to get there heads around how this will need to work for them.
In my script I will have the value $limit - this is the amount of results per page that we want per page.
the selectquery runs the search - Yours will be specfic to yourselves
from that selectquery we need to find out how many results there are.
[code]
$numresults=mysql_query($selectquery);
$numrows=mysql_num_rows($numresults);
[/code]
Next I want to find out if there is indeed more results that will fit onto 1 page and if so how many pages are there in total
[code]
if ($numrows > $limit){ // this calculates whether theres enough results to have pagination
$pagesExact = $numrows / $limit; // how many pages?
$pages = ceil($pagesExact); // gives the next highest round figure
}
[/code]
In the future at this stage in the script it may be the case that we are already on another page of search results. What I mean is that at the top of my search script I will check to see what page of the search this. I am going to send this to further pages in the URL using $_GET
>> $currpage = $_GET['currPage'];
Next I'll check to see if there is already a $currPage value - if not I'll take it as red were on page 1.
[code]
if (!$currPage) {
$currPage = 1;
}
[/code]
At this point in code I want to get the results that I am going to display. So that I only display the set that the page requires I am going to use the mysql command of LIMIT and OFFSET.
adding LIMIT to mysql will only give you that number of rows. By using OFFSET then we can offset the search ie by using an offset value of 10 then thats the row it will start at. Consider..
[code]
if ($currPage > 1){
$offset = ($currPage-1) * $limit;
$selectquery .= " LIMIT $limit OFFSET $offset ";
}else {
$selectquery .= " LIMIT $limit ";
}
[/code]
what I've done here is that if the search is more than 1 then I run the query with an offset. I calculated that the currpage ( example =2) take away 1 (example =1) times the limit (example 10) will equal (example 10) the offset that we need.
Now here comes the code to show the previous page if we need it
[code]
if ($currPage>1) {
$nPage=$currPage - 1;
print "\<a href="$PHP_SELF?currpage="$nPage\" wordsearch="TRUE&find="><<Prev 10  ";
}
[/code]
firstly we make it display if there is more than 1 page here to display. $currPage>1
Next we give the link the right number so when redirecting back to this script we know what page we're on. $nPage=$currPage - 1
The code for next>> page is similar
[code]
if ($currPage < $pages) { $nPage=$currPage + 1;
print " \<a href="$PHP_SELF?currpage="$nPage\" wordsearch="TRUE&find=">Next 10 >>";
}
[/code]
but we add a page to $nPage.
Next we give details of how many searches are being shown and how many results there are.
[code]
if ($currPage==1){
if ($offset > $numrows){
$offset = $numrows;
}
echo "
}
else {
$countresults = ($currPage - 1) * $limit; // we need to take away 1 from current page as page 3 needs to return results 20-30
$countAdd10 = $countresults + 10;
if ($countAdd10 > $numrows){
$countAdd10 = $numrows;}echo "
}
}
[/code]
And thats it. Any suggested improvements let me know.
to solve this in my search results I had tried downloading other peoples classes but after some head scratching and figuring out could not adapt them to the search script I had already wrote. In the end I decided it'd be better if I wrote the code myself. Here is how I reached my final aim - I am hoping to write this in such a way that it may help others try to get there heads around how this will need to work for them.
In my script I will have the value $limit - this is the amount of results per page that we want per page.
the selectquery runs the search - Yours will be specfic to yourselves
from that selectquery we need to find out how many results there are.
[code]
$numresults=mysql_query($selectquery);
$numrows=mysql_num_rows($numresults);
[/code]
Next I want to find out if there is indeed more results that will fit onto 1 page and if so how many pages are there in total
[code]
if ($numrows > $limit){ // this calculates whether theres enough results to have pagination
$pagesExact = $numrows / $limit; // how many pages?
$pages = ceil($pagesExact); // gives the next highest round figure
}
[/code]
In the future at this stage in the script it may be the case that we are already on another page of search results. What I mean is that at the top of my search script I will check to see what page of the search this. I am going to send this to further pages in the URL using $_GET
>> $currpage = $_GET['currPage'];
Next I'll check to see if there is already a $currPage value - if not I'll take it as red were on page 1.
[code]
if (!$currPage) {
$currPage = 1;
}
[/code]
At this point in code I want to get the results that I am going to display. So that I only display the set that the page requires I am going to use the mysql command of LIMIT and OFFSET.
adding LIMIT to mysql will only give you that number of rows. By using OFFSET then we can offset the search ie by using an offset value of 10 then thats the row it will start at. Consider..
[code]
if ($currPage > 1){
$offset = ($currPage-1) * $limit;
$selectquery .= " LIMIT $limit OFFSET $offset ";
}else {
$selectquery .= " LIMIT $limit ";
}
[/code]
what I've done here is that if the search is more than 1 then I run the query with an offset. I calculated that the currpage ( example =2) take away 1 (example =1) times the limit (example 10) will equal (example 10) the offset that we need.
Now here comes the code to show the previous page if we need it
[code]
if ($currPage>1) {
$nPage=$currPage - 1;
print "\<a href="$PHP_SELF?currpage="$nPage\" wordsearch="TRUE&find="><<Prev 10  ";
}
[/code]
firstly we make it display if there is more than 1 page here to display. $currPage>1
Next we give the link the right number so when redirecting back to this script we know what page we're on. $nPage=$currPage - 1
The code for next>> page is similar
[code]
if ($currPage < $pages) { $nPage=$currPage + 1;
print " \<a href="$PHP_SELF?currpage="$nPage\" wordsearch="TRUE&find=">Next 10 >>";
}
[/code]
but we add a page to $nPage.
Next we give details of how many searches are being shown and how many results there are.
[code]
if ($currPage==1){
if ($offset > $numrows){
$offset = $numrows;
}
echo "
Showing results $currPage to $offset of $numrows
";}
else {
$countresults = ($currPage - 1) * $limit; // we need to take away 1 from current page as page 3 needs to return results 20-30
$countAdd10 = $countresults + 10;
if ($countAdd10 > $numrows){
$countAdd10 = $numrows;}echo "
Showing results $countresults to $countAdd10 of $numrows
";}
}
[/code]
And thats it. Any suggested improvements let me know.
Subscribe to:
Posts (Atom)