ERLEDIGT
NEIN
NEIN
ANTWORTEN
4
4
ZUGRIFFE
520
520
EMPFEHLEN
-
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');
}
?>
-
24.10.07 11:17 #2
- Registriert seit
- Jun 2007
- Ort
- Lingen (Niedersachsen, zZ in Istanbul)
- Beiträge
- 685
PHP-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 poste den Source nochmal in [php] Klammern
Ich denke mal dein Session_id Feld in der Tabelle wird int als Parameter haben oder?
Dementsprechend dürfen da keine Anführungszeichen hin:
Weiter unten im Script steht dasselbe nochmal.PHP-Code://Falsch
$adSql = 'SELECT admin FROM users WHERE session_ID = \'' . session_id() . '\''
//richtig
$adSql = 'SELECT admin FROM users WHERE session_ID = ' .session_id().'';
-
-
Nein ich habe die session ID als vrachar in der DB gespeichert, es kann aslo nicht dieser Fehler sein. Ich bin wie gesagt ziemlich verzweifelt, es t überhaupt nicht.
Danke auch für den zweiten Tipp aber das löst das Problem auch nicht ganz
-
24.10.07 12:02 #5
Sorry, aber das ist falsch. Eine SessionID besteht im Allgemeinen aus Zeichen a-z, A-Z und Ziffern 0-9. Siehe dazu u.A. session_id() (Rückgabewert: String).
Gruß mAu
──────────────────────────
Ich auf flickr
* Unformatierten Quellcode schaue ich mir _nicht_ an!
* Sollte ich euch bei einer Frage weitergeholfen haben, würde ich mich über eine positive Bewertung freuen.
* Bitte die Netiquette beachten.
* Vergesst nicht, beantwortete Fragen als erledigt zu markieren!
Ähnliche Themen
-
byte Array in Datei speichern und wieder in byte Array einlesen
Von riseX im Forum JavaAntworten: 5Letzter Beitrag: 22.02.10, 12:05 -
Tabelle in mehrd. Array einlesen und mit Variablen vergleichen
Von Alfred_ im Forum .NET DatenverwaltungAntworten: 0Letzter Beitrag: 17.05.08, 17:26 -
array einlesen array schreiben
Von DerWisser im Forum C/C++Antworten: 3Letzter Beitrag: 27.03.07, 17:40 -
[C++] Daten aus .txt in 2D-Array einlesen
Von Lodda2003 im Forum C/C++Antworten: 8Letzter Beitrag: 09.10.04, 19:57 -
[C] 2d Array in Funktion einlesen
Von ShabbY im Forum C/C++Antworten: 19Letzter Beitrag: 20.04.03, 21:21





Zitieren

Login






[PHP][Snippet] Array zu XML konvertieren