Hallo zusammen ich bin nun schon eine ganze Weile an diesem Scrript. Ich habe das Ziel eine Sql Tabell in ein Array einzulesen und dann im Template mit smarty weiterzu verarbeiten. Mein Problem ist nun, dass die sql Befehle nicht zu funktionieren scheinen auf jeden Fall werden die Werte nicht ins Array geschrieben....
Ich hoffe auf Hlfe und danke im voraus hier mein Code:
<?php
session_start();
//include 'checkuser.php';
include 'sessionhelpers.inc.php';
require 'libs/Smarty.class.php';
$smarty = new Smarty;
$smarty->template_dir='templates/';
connect();
//Find out if User is an admin
$adSql = 'SELECT admin FROM users WHERE session_ID = \'' . session_id() . '\'';
$admin = mysql_query($adSql);
//if User is an admin he's aloud to see all datas
if($admin==1)
{
$query_adminPasswords = 'SELECT * FROM passwords ORDER BY host';
$adminPasswords = mysql_query($query_adminPasswords) or die (mysql_error());
$arrAdminPasswords = array();
$i=0;
while($r=mysql_fetch_array($adminpasswords))
{
$tmp = array (
'host_ID' => $r['host_ID'],
'host' => $r['host'],
'title' => $r['title'],
'username' => $r['username'],
'passwords' => $r['passwords'],
'type' => $r['type'],
'comments' => $r['comments'],
'crdate' => $r['crdate']
);
$arrAdminPasswords[$i++]=$tmp;
}
// pass the results to the template
$smarty->assign('adminPasswords', $arrAdminPasswords);
// load the template
$smarty->display('adminpasswords.tpl.html');
}
//if not, we have to find out what usergruop he belongs to
else
{
//Find out which usergoup user belongs to
$sql = 'SELECT groups FROM users WHERE session_ID = \'' . session_id() . '\'';
//put all datas user have access to in array
$query_passwords = 'SELECT host_ID, host, title, username, passwords, type, comments, crdate FROM passwords WHERE access =('.$sql.') ORDER BY host';
$passwords = mysql_query($query_passwords);
$arrPasswords = array();
$i=0;
//write datas in array
while($r=mysql_fetch_array($passwords))
{
$arrPasswords[$i]['host_ID'] = $r['host_ID'];
$arrPasswords[$i]['host'] = $r['host'];
$arrPasswords[$i]['title'] = $r['title'];
$arrPasswords[$i]['passwords'] = $r['passwords'];
$arrPasswords[$i]['username'] = $r['username'];
$arrPasswords[$i]['type'] = $r['type'];
$arrPasswords[$i]['comments'] = $r['comments'];
$arrPasswords[$i]['crdate'] = $r['crdate'];
$i++;
}
echo ($arrPasswords[0]['host']);
echo ($arrPasswords[1]['type']);
echo ($arrPasswords[0]['host_ID']);
// pass the results to the template
$smarty->assign('passwords', $arrPasswords);
// load the template
$smarty->display('passwords.tpl.html');
}
?>
Ich hoffe auf Hlfe und danke im voraus hier mein Code:
<?php
session_start();
//include 'checkuser.php';
include 'sessionhelpers.inc.php';
require 'libs/Smarty.class.php';
$smarty = new Smarty;
$smarty->template_dir='templates/';
connect();
//Find out if User is an admin
$adSql = 'SELECT admin FROM users WHERE session_ID = \'' . session_id() . '\'';
$admin = mysql_query($adSql);
//if User is an admin he's aloud to see all datas
if($admin==1)
{
$query_adminPasswords = 'SELECT * FROM passwords ORDER BY host';
$adminPasswords = mysql_query($query_adminPasswords) or die (mysql_error());
$arrAdminPasswords = array();
$i=0;
while($r=mysql_fetch_array($adminpasswords))
{
$tmp = array (
'host_ID' => $r['host_ID'],
'host' => $r['host'],
'title' => $r['title'],
'username' => $r['username'],
'passwords' => $r['passwords'],
'type' => $r['type'],
'comments' => $r['comments'],
'crdate' => $r['crdate']
);
$arrAdminPasswords[$i++]=$tmp;
}
// pass the results to the template
$smarty->assign('adminPasswords', $arrAdminPasswords);
// load the template
$smarty->display('adminpasswords.tpl.html');
}
//if not, we have to find out what usergruop he belongs to
else
{
//Find out which usergoup user belongs to
$sql = 'SELECT groups FROM users WHERE session_ID = \'' . session_id() . '\'';
//put all datas user have access to in array
$query_passwords = 'SELECT host_ID, host, title, username, passwords, type, comments, crdate FROM passwords WHERE access =('.$sql.') ORDER BY host';
$passwords = mysql_query($query_passwords);
$arrPasswords = array();
$i=0;
//write datas in array
while($r=mysql_fetch_array($passwords))
{
$arrPasswords[$i]['host_ID'] = $r['host_ID'];
$arrPasswords[$i]['host'] = $r['host'];
$arrPasswords[$i]['title'] = $r['title'];
$arrPasswords[$i]['passwords'] = $r['passwords'];
$arrPasswords[$i]['username'] = $r['username'];
$arrPasswords[$i]['type'] = $r['type'];
$arrPasswords[$i]['comments'] = $r['comments'];
$arrPasswords[$i]['crdate'] = $r['crdate'];
$i++;
}
echo ($arrPasswords[0]['host']);
echo ($arrPasswords[1]['type']);
echo ($arrPasswords[0]['host_ID']);
// pass the results to the template
$smarty->assign('passwords', $arrPasswords);
// load the template
$smarty->display('passwords.tpl.html');
}
?>