Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

next data

// useful at my work

$results = $db->____();

if($results->numRows())
{
    $results->next();
    $field_val = $results->data['field_name'];
    $array = $results->data['field_name'];
}

News

// A small mysql/php based News system I wrote to fit in a given website

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html compress="gzip" lang="de"><head>

  <link href="../../allg/css/stylesheet.css" rel="stylesheet" media="screen"><title>Info-Center</title>

	<style>
		#downloadcenter select
		{
			font-size: 10px;
		}
		.tinyText
		{
			text-align: left;
			font-size: 11px;
		}
		body
		{
			font-size: 10px;
		}
	</style>
	<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  <meta name="title" content="Info-Center">
  <meta name="memory" content="755">
  <meta name="pid" content="6778">
  <meta name="exec" content="0.64515">
  <meta name="length" content="18">
  <script language="JavaScript1.2" type="text/javascript">JSBASE="/";</script>
  <!-- SmartWebDynamicHead-ID:67781209996468-End --></head>
  	<body style="margin: 0px;" alink="#333333" background="../../allg/Bilder/templ_bg_main.gif" bgcolor="#ffffff" link="#333333" text="#333333" vlink="#333333">
  <table style="height: 100%;" border="0" cellpadding="0" cellspacing="0" height="100%" width="725">
   <tbody>
   	<tr>
    <td valign="top" width="725"><!-- Rechter Bereich -->
     <table border="0" cellpadding="0" cellspacing="0" width="725">
      <tbody>
      	<tr>
         <td valign="top" width="30"><img src="../../allg/Bilder/templ_C-ZZZZZZ.gif" alt="" border="0" height="1" width="30"></td>
         <td valign="top" width="695">
           <table border="0" cellpadding="0" cellspacing="0" width="693"><!-- Head -->
             <tbody>
 <tr>
  <td>
   <table border="0" cellpadding="0" cellspacing="0">
    <tbody><tr>
     <td valign="top"><img src="../../allg/Bilder/head_partnerweb_1.gif" alt="" border="0" height="101" width="378"></td>
     <td><img src="../../allg/Bilder/head_intern_2.jpg" alt="" border="0" height="155" width="315"></td>
    </tr>
   </tbody></table>
  </td>
 </tr>
 <tr>
  <td><img src="../../allg/Bilder/templ_C-ZZZZZZ.gif" alt="" border="0" height="10" width="12"><br></td>
 </tr>
             </tbody>
           </table>

<table style="border-color:black;" border=0 width="690">
  <thead>
  <tr style="font-size:10; font-weight:bold; text-align:center; background-color:aaaaaa;">
   <td>ID</td>
   <td width="80">Modify Date</td>
   <td width="90">Titel</td>
   <td width="160">Anleser</td>
   <td>Content</td>
   <td width="30">Verfall<br>nach</td>
   <td width="10">&nbsp;</td>
  </tr>
  </thead>
  <tbody style="vertical-align:top; background-color:cccccc;">
	<?php
	//require_once("../../allg/infoCenter/constructor.php");
	function date_mysql2german($date)
  {
    $d = explode("-",$date);
    return sprintf("%02d.%02d.%04d", $d[2], $d[1], $d[0]);
	}
	
	$host = "tstdokusrv";
  $user = "pit";
  $passwd = "pit2008";
  $dbname = "produktdaten";
	
	$db = mysql_connect($host,$user,$passwd);
	mysql_select_db("produktdaten");
	$sqlstr ="SELECT * FROM tbl_news;";
	//echo "SQLstr: ".$sqlstr."<br>";
	mysql_query("SET NAMES 'utf8'");
	mysql_query("SET CHARACTER SET 'utf8'");
	$result = mysql_query($sqlstr);
	while($row = mysql_fetch_row($result))
	{
	  echo "<tr>";
	    echo "<td align='center'>".$row[0]."</td>";
	    echo "<td align='center'>".date_mysql2german(substr($row[1],0,10))."</td>";
	    echo "<td>".$row[2]."</td>";
	    echo "<td>".$row[3]."</td>";
	    echo "<td><!--textarea cols=40 readonly-->".$row[4]."<!--/textarea--></td>";
	    echo "<td align='center'>".$row[5]."</td>";
	    echo "
	    <td>
	      <a href='News_anlegen.php?id=$row[0]&action=test'><img alt='edit' border='0' src='../../allg/Bilder/b_edit.png'></a><br>
	      <a href='news_detail.php?id=$row[0]'><img alt='Anzeigen' border='0' src='../../allg/Bilder/b_search.png'></a>
	      <a href='News_anlegen.php?id=$row[0]&action=delete'><img alt='Anzeigen' border='0' src='../../allg/Bilder/b_drop.png'></a>
	    </td>";
	  echo "</tr>";
	}
	?>
  </tbody>
</table>
<br>
<table>
   <tr>
     <td style="font-size:16;">
       <a href="News_anlegen.php?id=-1">News anlegen</a><br>
     </td>
   </tr>
</table>
    </td>
   </tr>
  </tbody></table>
    <div id="moz_shader"></div>
   </body></html>

Convert MySQL tables to InnoDB

// Slower than MyISAM, but row locking is clutch if you're doing a lot of writes amirite?

for t in $(mysql --batch --column-names=false -e "show tables" mydbname |grep -v "exclude_this");
do
mysql -e "alter table $t type=InnoDB" mydbname;
done


From:
http://ludo.qix.it/archive/2005/04/convert-a-bunch-of-tables-to-innodb.html

Delete duplicate rows from a table

// Whoops, didja forgot to add a unique index to that column? No problem

CREATE TABLE new_table AS
SELECT * FROM old_table WHERE 1 GROUP BY [COLUMN TO remove duplicates BY];
DROP TABLE old_table;
RENAME TABLE new_table TO old_table;

VB.net Modified Preorder Tree Traversal

In order to utilize this, I would recommend reading the article located at sitepoint.com (Search google for modified preorder tree traversal). It took me quite some time and some help from a coworker to port this from PHP to VB.net. :D

Replace the application("sql").query("*") with your SQL code, I was inclined to write my own SQL class to make querying DB's easier, but you can do whatever you want.
record = application("sql").query("select * from categories order by lft asc")
dim output as new arraylist()
dim right as new arraylist()
do while not record.eof
  if right.count > 0
    do while right(right.count - 1) < record("rgt").value
      right.removeAt(right.count - 1)
      if right.count = 0 then exit do
    loop
  end if
  response.write(record("name").value & " is " & right.count & " levels deep in the tree..." & controlchars.cr)
  right.add(record("rgt").value)
  record.movenext
loop