Snippetz

PHP/MySQL code snippets to save the day…

3 column to 2 column?

here is sidebar.php:

  1. <div id="sidebar_left" class="sidebar">
  2.  
  3.  
  4. <div id="logo">
  5. <h3><a href="http://gcm.syr.edu/_/snippetz/wp-admin/%3C?php bloginfo(’url’) ?&gt;/"><!–p bloginfo(‘name’)–></a><!–alternative color <a class="logoalt" href="/" mce_href="/"></a> –></h3>
  6. </div>
  7. <div id="aboutme">
  8. <ul>
  9.         <li><img src="http://gcm.syr.edu/_/snippetz/wp-admin/%3C?php bloginfo(’template_url’) ?&gt;/images/aboutme.gif" alt="About me" /><strong>About</strong>
  10. <!–p bloginfo(‘description’)–></li>
  11. </ul>
  12. </div>
  13. <div id="navcontainer">
  14. <ul id="navlist"><!–p wp_list_pages(‘title_li=&#038;depth=1′);–></ul>
  15. </div>
  16. <!–p if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(’sidebar_left’) ) :–>
  17. <h2>Categories</h2>
  18. <ul>
  19.         <li> 
  20. <ul>
  21.         <li><!–p_tag_cloud();–></li>
  22. </ul>
  23. </li>
  24. <!–p wp_list_cats(‘&#038;title_li=’); ?></ul>
  25. <div mce_tmp="1"><?php if (function_exists(‘wp_tag_cloud’)) {–>
  26. <h2>Tag Cloud</h2>
  27. <!–p }–></ul>
  28.  
  29.  
  30. <!–p endif;–>
  31.  
  32.  
  33.  
  34. </div>
  35. <div id="sidebar_right" class="sidebar">
  36. <div class="search"><form id="searchform" action="&lt;?php bloginfo(’url’); ?&gt;" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="get"><input id="search_query" class="searchinput" maxlength="2147483647" name="s" size="20" type="text" value="&lt;?php echo wp_specialchars($s, 1); ?&gt;" /> <input class="searchbutton" maxlength="2147483647" size="20" type="submit" value="Find" /> </form></div>
  37. </div>
  38. <!–p if ( !function_aexists(‘dynamic_sidebar’) || !dynamic_sidebar(’sidebar_right’) ) :–>
  39. <h2>Archives</h2>
  40. <ul><!–p wp_get_archives(‘type=monthly’);–></ul>
  41. <ul><!–p<br–>if (wp_version()==‘20′) {
  42. echo
  43. <h2>Links</h2>
  44. ;
  45. get_links(‘1′,
  46.         <li>’,‘</li>
  47. ,,false,‘name’,false);
  48. }
  49. else {
  50. wp_list_bookmarks(array(‘title_before’ =&gt;
  51. <h2>’, ‘title_after’ =&gt; ‘</h2>
  52. , ‘category_before’ =&gt; , ‘category_after’ =&gt; ));
  53. }
  54. ?&gt;</ul>
  55. <!–p endif;–>
  56. <div id="logo">
  57. <h3><a href="http://gcm.syr.edu/_/snippetz/wp-admin/%3C?php bloginfo(’url’) ?&gt;/"><!–p bloginfo(‘name’)–></a><!–alternative color <a class="logoalt" href="/" mce_href="/"></a> –></h3>
  58. </div>
  59. <div id="aboutme">
  60. <ul>
  61.         <li><img src="http://gcm.syr.edu/_/snippetz/wp-admin/%3C?php bloginfo(’template_url’) ?&gt;/images/aboutme.gif" alt="About me" /><strong>About</strong>
  62. <!–p bloginfo(‘description’)–></li>
  63. </ul>
  64. </div>
  65. <div id="navcontainer">
  66. <ul id="navlist"><!–p wp_list_pages(‘title_li=&#038;depth=1′);–></ul>
  67. </div>
  68. <!–p if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(’sidebar_left’) ) :–>
  69. <h2>Categories</h2>
  70. <ul>
  71.         <li> 
  72. <ul>
  73.         <li><!–p_tag_cloud();–></li>
  74. </ul>
  75. </li>
  76. <!–p wp_list_cats(‘&#038;title_li=’); ?></ul>
  77. <div mce_tmp="1"><?php if (function_exists(‘wp_tag_cloud’)) {–>
  78. <h2>Tag Cloud</h2>
  79. <!–p }–></ul>
  80.  
  81.  
  82. <!–p endif;–>
  83.  
  84.  
  85. <div id="sidebar_right" class="sidebar">
  86. <div class="search"><form id="searchform" action="&lt;?php bloginfo(’url’); ?&gt;" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="get"><input id="search_query" class="searchinput" maxlength="2147483647" name="s" size="20" type="text" value="&lt;?php echo wp_specialchars($s, 1); ?&gt;" /> <input class="searchbutton" maxlength="2147483647" size="20" type="submit" value="Find" /> </form></div>
  87. </div>
  88. <!–p if ( !function_aexists(‘dynamic_sidebar’) || !dynamic_sidebar(’sidebar_right’) ) :–>
  89. <h2>Archives</h2>
  90. <ul><!–p wp_get_archives(‘type=monthly’);–></ul>
  91. <ul><!–p<br–>if (wp_version()==‘20′) {
  92. echo
  93. <h2>Links</h2>
  94. ;
  95. get_links(‘1′,
  96.         <li>’,‘</li>
  97. ,,false,‘name’,false);
  98. }
  99. else {
  100. wp_list_bookmarks(array(‘title_before’ =&gt;
  101. <h2>’, ‘title_after’ =&gt; ‘</h2>
  102. , ‘category_before’ =&gt; , ‘category_after’ =&gt; ));
  103. }
  104. ?&gt;</ul>
  105. <!–p endif;–>
Tags:

PHP MySQLi Query w/chaining

  1. code to be inserted later ;-)
Tags: , ,

PHP LDAP Query

  1. code to be inserted later ;-)
Tags: ,

PHP pagination form MySQL db

  1. &lt;?php
  2. //pagination part below
  3. if (isset($_GET[‘pageno’])) {
  4.    $pageno = $_GET[‘pageno’];
  5. } else {
  6.    $pageno = 1;
  7. } // if
  8. //pagination part above
  9.  
  10.     $link = @mysql_connect(‘localhost:3306′, ‘root’, );
  11.     if (!$link) {
  12.       die( ‘&lt;p&gt;Unable to connect to the ‘ .
  13.            ‘database server at this time.&lt;/p&gt;’ );
  14.     }
  15.     if (! @mysql_select_db(‘gcmsyredu’) ) {
  16.       die( ‘&lt;p&gt;Unable to locate the quotes ‘ .
  17.            ‘database at this time.&lt;/p&gt;’ );
  18.     }
  19. //pagination part below
  20. $query = "SELECT count(*) FROM quotes";
  21. $result = mysql_query($query, $link) or trigger_error("SQL", E_USER_ERROR);
  22. $query_data = mysql_fetch_row($result);
  23. $numrows = $query_data[0];
  24.  
  25. $rows_per_page = 7;
  26. $lastpage      = ceil($numrows/$rows_per_page);
  27. $pageno = (int)$pageno;
  28. if ($pageno &gt; $lastpage) {
  29.    $pageno = $lastpage;
  30. } // if
  31. if ($pageno &lt; 1) {
  32.    $pageno = 1;
  33. } // if
  34. $limit = ‘LIMIT ‘ .($pageno - 1) * $rows_per_page .‘,’ .$rows_per_page;
  35. $query = "SELECT * FROM quotes $limit";
  36. $result = mysql_query($query, $link) or trigger_error("SQL", E_USER_ERROR);
  37. //pagination part above
  38.  
  39. $result = mysql_query($query);
  40. if (!$result) {
  41.     $message  = ‘Invalid query: ‘ . mysql_error() . "\n";
  42.     $message .= ‘Whole query: ‘ . $query;
  43.     die($message);
  44. }
  45. echo "&lt;br&gt;&lt;u&gt;&lt;b&gt;Quotes:&lt;/b&gt;&lt;/u&gt;&lt;br&gt;";
  46. while ($row = mysql_fetch_object($result)) {
  47.  //var_dump($row);
  48.  echo $row-&gt;quote . ‘&lt;br&gt;’;
  49.     //echo $row['quote'] . ‘&lt;br&gt;’;
  50.  
  51. }
  52. //pagination part below
  53. if ($pageno == 1) {
  54.    echo " FIRST PREV ";
  55. } else {
  56.    echo " &lt;a href=’{$_SERVER['PHP_SELF']}?pageno=1′&gt;FIRST&lt;/a&gt; ";
  57.    $prevpage = $pageno-1;
  58.    echo " &lt;a href=’{$_SERVER['PHP_SELF']}?pageno=$prevpage’&gt;PREV&lt;/a&gt; ";
  59. } // if
  60.  
  61. echo " ( Page $pageno of $lastpage ) ";
  62. if ($pageno == $lastpage) {
  63.    echo " NEXT LAST ";
  64. } else {
  65.    $nextpage = $pageno+1;
  66.    echo " &lt;a href=’{$_SERVER['PHP_SELF']}?pageno=$nextpage’&gt;NEXT&lt;/a&gt; ";
  67.    echo " &lt;a href=’{$_SERVER['PHP_SELF']}?pageno=$lastpage’&gt;LAST&lt;/a&gt; ";
  68. } // if
  69.  
  70. //pagination part above
  71.  ?&gt;
Tags: , , , , ,

Testing code highlighting:

  1. // Connect to server and select database.
  2. mysql_connect("$host", "$username", "$password")or die("cannot connect to server ");
  3. mysql_select_db("$db_name")or die("cannot select DB");
  4.  
  5. $sql="SELECT counter FROM $tbl_name";
  6. $result=mysql_query($sql);
  7.  
  8. $rows=mysql_fetch_array($result);
  9. $counter=$rows[‘counter’];
  10.  
  11. // if have no counter value set counter = 1
  12. if(empty($counter)){
  13. $counter=1;
  14. $sql1="INSERT INTO $tbl_name(counter) VALUES(’$counter’)";
  15. $result1=mysql_query($sql1);
  16. }
  17.  
  18. echo $counter;
  19. echo " Visitors since July 2005";
  20.  
  21. // count more value
  22. $addcounter=$counter+1;
  23. $sql2="update $tbl_name set counter=’$addcounter’";
  24. $result2=mysql_query($sql2);
Tags: , , , ,