Posted By

microbians on 08/17/10


Tagged

cms-addons-plugins-thesecretaryorg


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

microbians


thesecretary.org / projectFirstThumb


 / Published in: PHP
 

URL: http://www.thesecretary.org/

  1. function projectFirstThumb($idslug){
  2. global $clerk;
  3.  
  4. // Only one row (because one id unique)
  5. $project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.slug="'.$idslug.'"' ) );
  6. // Not found try by ID not slug
  7. if ($project=="") {
  8. $project = mysql_fetch_alias_array( $clerk->query_select( 'projects', '', 'WHERE projects.id="'.$idslug.'"' ) );
  9. }
  10.  
  11. if ($project['projects.thumbnail'] != '') {
  12. return PROJECTS_URL.$project['projects.slug'].'/'.$project['projects.thumbnail'];
  13. } else {
  14. $filesGet = $clerk->query_select( 'project_files', '', 'WHERE type="image" AND project_id='.$project['projects.id'].' ORDER BY filegroup,pos ASC LIMIT 1');
  15. while ( $file = mysql_fetch_alias_array($filesGet)) {
  16. return PROJECTS_URL.$project['projects.slug'].'/'.$file['project_files.thumbnail'];
  17. }
  18. }
  19. return '';
  20. }
  21.  
  22.  
  23.  
  24. function mysql_fetch_alias_array($result) {
  25. // Avoid the problem of duplicated field names in joint queries
  26. // From Post by Mehdi Haresi in PHP.net
  27. if (!($row = mysql_fetch_array($result))) {
  28. return null;
  29. }
  30.  
  31. $assoc = Array();
  32. $rowCount = mysql_num_fields($result);
  33.  
  34. for ($idx = 0; $idx < $rowCount; $idx++) {
  35. $table = mysql_field_table($result, $idx);
  36. $field = mysql_field_name($result, $idx);
  37. $assoc["$table.$field"] = $row[$idx];
  38. }
  39. return $assoc;
  40. }

Report this snippet  

You need to login to post a comment.