variable in sql statement

alkaline

Mitglied
Guten Morgen,
ich bekomme es nicht gebacken, eine Variable in ein sql statement zu packen. Ist dies überhaupt möglich? In meinem Beispiel speichere ich in $tab den Tabellennamen und übergebe unten $tab an die Funktion "anzeigen"....

PHP:
<?php
include ('mysql.inc.php');
$tab = 'cds';
function anzeigen($tabelle)
{

	$result = mysql_query('SELECT * FROM $tabelle);
	if($result)
	{

		echo '<table>';
		while($row = mysql_fetch_row($result))
		{
			echo '<tr>';
			for($col = 0; $col < SizeOf($row); $col++)
			{
				echo"<td>$row[$col]</td>";
			}
			echo '</tr>';
		}
		echo '</table>';
	}
}

$connection = mysql_connect($sql['host'],$sql['uid'],$sql['pwd']);
if($connection)
{
	if(mysql_select_db($sql['db']))
	{
		echo 'datenbank erfolgreich ausgewählt<br>';
	}
}

anzeigen($tab);
?>
 
Zurück