All pastes #964170 Raw Edit

Miscellany

public php v1 · immutable
#964170 ·published 2008-03-31 01:36 UTC
rendered paste body
/*           /----------------************** showtable()/*           \----------------------> Displays table from dbExample Usage:$dbfields = array('id', 'rule', 'topic_id', 'votes', 'poster', 'time');    // Fields to be displayed$tabletitles=array('Id', 'Rule', 'Topic', 'Votes', 'Poster', 'Time', 'mod', 'del');  // Desired Titles of table to be shown$extra=array('items'=> array (2), 'i1'=>array('table'=>'topics', 'f1'=>'id_topic', 'f2'=>'topic')  ); // Replace third row (which has numeriacl values) with values from another table, that corresponds to those numbersshowtable('mytable', 'id', $dbfields , $tabletitles, $extra);// mytable = table name, id = name of primary key*/function showtable ($table, $order, $fields, $naslovi="", $extra="", $where="") {$con=dbopen();$query="SELECT ";foreach($fields as $value)	{		$query.=$value.", ";		}		$query = rtrim($query, ', ');$query.=" FROM $table $where ORDER BY $order";$result = dbq($query, $con);dbclose($con);if (is_array($naslovi)) $number_naslovi = count($naslovi);if (is_array($fields)) $number_cols = count($fields);else $number_cols = mysql_num_fields($result);//echo "<b>Tabela: $table2show</b>";echo "<div id='tabela' align='center'> <table>\n";echo "<tr align=center>\n";for ($i=0; $i<$number_naslovi; $i++){echo "<th>" . $naslovi[$i] . "</th>\n";}echo "</tr>\n"; //end table header/*$number_cols = mysql_num_fields($result);echo "<table border = 1>\n";echo "<tr align=center>\n";echo "<th>ID</th>\n<th>".$naslovc."</th>\n";echo "</tr>\n"; //end table header*///table bodywhile ($row = mysql_fetch_row($result)){//if (!isset($boja)) $boja = '#99ccff';// $boja = ($boja=='#99CCFF' ? '#CCCCCC' : '#99CCFF'); if (!isset($boja)) $boja = 'tr2'; $boja = ($boja=='tr1' ? 'tr2' : 'tr1'); // echo '<tr align=left bgcolor="'. $boja .'">' . "\n"; // echo '<tr align=left bgcolor="'. $boja .'" onMouseOver="this.bgColor=\'#FFFFCC\';" onMouseOut="this.bgColor=\''.$boja.'\';">' . "\n";   echo '<tr class="'.$boja.'" onmouseover="this.className=\'hoverz\';" onmouseout="this.className=\''.$boja.'\';">' . "\n"; for ($i=0; $i<$number_cols; $i++){echo "<td>";if (!isset($row[$i])) //test for null{echo "NULL";}else {	if (is_array($extra)) {	$doned = 0;		$xz = count($extra['items']);		for ($z=0; $z<$xz; $z++)			{				if ($i == $extra['items'][$z]) {						$nj = $z + 1;					$itm = 'i'. $nj;					$con=dbopen();					$ff2= $extra[$itm]['f2'];					$tbl2= $extra[$itm]['table'];					$ff1=  $extra[$itm]['f1'];					$query = "SELECT $ff2 FROM $tbl2 WHERE $ff1='$row[$i]'";					$result2 = 	dbq($query, $con);					dbclose($con);					$line2= mysql_fetch_array($result2);					echo $line2['0'];					$doned = 1;				}			}		}	if ($doned != 1) { //echo $row[$i];$row[$i] = strip_tags($row[$i]);if (strlen($row[$i]) > 100)	$row[$i]=substr( $row[$i], 0, strpos( $row[$i], ' ', 100 ) )."...";echo $row[$i];unset($doned);}}echo "</td>\n";	}	echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?action=mod&amp;item=' .$row[0]. '" title="Modify"  style="font-size:xx-small; font-family:Verdana, Arial, Helvetica, sans-serif;"><img class="icon" src="../images/table/table_edit.png"alt="Modify" title="Modify" height="16" width="16"></a></td><td><a href="' . $_SERVER['PHP_SELF'] . '?action=del&amp;item=' .$row[0]. '" onClick="return confirmSubmit()" title="Delete" style="font-size:xx-small; font-family:Verdana, Arial, Helvetica, sans-serif;"><img class="icon" src="../images/table/table_del.png"alt="Delete" title="Delete" height="16" width="16"></a></td>';echo "</tr>\n";}echo "</table>";}