Posts Tagged ‘PHP’

PHP error: expecting T_PAAMAYIM_NEKUDOTAYIM

Posted in Programming on May 10th, 2010 by Jason – Be the first to comment

I ran across this error the other day while setting up a nested foreach loop. When looking at the error logs all I found was expecting T_PAAMAYIM_NEKUDOTAYIM. Which was not very helpful. If you find that you have this error, try looking for a missing dollar sign “$” on one of your variables.

Hope this helps, happy coding!

Post to Twitter Tweet This Post

Setting A default image with PHPThumb

Posted in Programming, Websites on August 7th, 2009 by Jason – Be the first to comment

For one of the larger projects that I work on, I use phpThumb, which will create a thumbnail of the requested image and cache it for fast downloads. This is great when you have a large number of images that will be viewed at various sizes and you dont want to export all the various sizes.

One of the problems I ran into recently is setting a default image that will appear if for some reason your source file cannot be located. When you are pulling images from a separate provider, this can become a concern.

PhpThumb has made this easy as their is a setting in the config file as shown below.

phpthumbconfig

All you have to do is add the local path to the file you want as a default into the config and then to test it you can set phpThumb to attempt to load a bad source file and it should display your image. If you are having issues seeing the file, make sure that the names match up, and that you have a forward slash before the path. You can also try doing an absolute path with the entire url to the image.

Post to Twitter Tweet This Post

Reuse your Select statements with mysql_data_seek( )

Posted in Programming on January 2nd, 2009 by Jason – Be the first to comment

This function has come in very handy with the developement of this site. You can use this function to set the data pointer to a certain row within your result that you recieve from a database function, in my case, mysql_query().

There are a couple reasons you would want to use the mysql_data_seek(). One would be to return to the first row returned from the database, or it could be used to return to any row. There are also other uses for this function but to keep it simple I will just talk about the first.

The following code is a standard mysql query created by dreamweaver.

mysql_select_db($database, $connection);
$query="SELECT * FROM tables;
$resource=mysql_query($query, $connection) or die(mysql_error());
$row_recordset= mysql_fetch_assoc($resource);
$totalRows_recordset = mysql_num_rows($resource);

When you request information from the database it is stored as a resource. You can then pull from that resource with the mysql_fetch_assoc($resource). You can also use other functions such as mysql_fetch_row($resource).

PHP handles a resource very similar to reading a file. As PHP reads from the resource, it marks its place, much like earmarking a page in a book PHP remembers the last spot that was read from the resource. When you get to the last page of the book, you turn back to page one, and when you get to the last of the resource you have to set the pointer back to the beginning.

mysql_data_seek("$resource",0);
$row_recordset=mysql_fetch_assoc($resource);

The mysql_data_seek() uses two values to accomplish this.The first value “$resource” is exactly what it says it is, the resource of your mysql select statement. The second is a numeric value of where you want to move the pointer or bookmark for that resource. The next time you get a value from the resource it will be from the new location of the pointer.

An important note if you are using dreamweaver. As you saw earlier in the code, dreamweaver initially sets $row_resource. With it initially set, you can use a do while loop so that the first instance is set and each reoccurring instance is set by the while statement. This is why after using the mysql_data_seek, I re-assigned $row_resource with the next value after the dataseek, in this case setting it back to the first value from the mysql select statement.

Post to Twitter Tweet This Post