Hallo again
I am trying to list out products, and want to make sure, that if database or table not exists, there will be no long error list printet out.
This should be so easy, but I guess not in modx
can any help me
I connect to a seperate mysql database
here is the code and a list of some codelines I tryed
code in snippet
// snippets parameters
$dbname = isset ($dbname )?$dbname :$_GET[’dbname ’]; //database name
$username = isset ($username )?$username :$_GET[’username ’];
$password = isset ($password )?$password :$_GET[’password ’];
$tblname = isset ($tblname )?$tblname :$_GET[’tblname ’];//tablename
$tablestyleclass = isset ($tablestyleclass)?$tablestyleclass:$_GET[’tablestyleclass’];//table class
$tbodystyleclass = isset ($tbodystyleclass)?$tbodystyleclass:$_GET[’tbodystyleclass’];//tbody class
$headcolumn_1 = isset ($headcolumn_1)? $headcolumn_1:$_GET[’headcolumn_1’];//tablehead column 1
$headcolumn_2 = isset ($headcolumn_2)? $headcolumn_2:$_GET[’headcolumn_2’];//tablehead column 2
$headcolumn_3 = isset ($headcolumn_3)? $headcolumn_3:$_GET[’headcolumn_3’];//tablehead column 3
$output = ’’;
// check if database exists
//connect to seperate mysql db
if (!@mysql_select_db(’$dbname.$tblname’)){
//if (!@$modx->db->connect(’localhost’, ’$dbname’, ’$username’, ’$password’, true)){
echo " No list a the moment !";
}
else{
//$ds = $modx->db->select(’*’,’$dbname.$tblname’);
$ds = mysql_select_db(’$dbname.$tblname’);
$resultArray = $modx->db->makeArray($ds);
foreach($resultArray as $item) {
$params[’value1’]= $item[’b’];
$params[’value2’]= $item[’d’];
$output .= $modx->parseChunk(’xls_list_of_products_tpl’, $params, ’[+’, ’+]’);
//$output .= $params;
}
return $output;
}
List of some of the codes I tryed and didn’t work
if (!(@mysql_select_db(`$dbname.$tblname`))){
echo " No list a the moment !";
}
if (!($modx->db->select(`$dbname.$tblname`))){
echo " No list a the moment !";
}
if(mysql_connect(’localhost’,’$dbname’,’$pass’)){
echo " No list a the moment !";
}
if (!($modx->db->connect(`$dbname.$tblname`))){ ------------- `
echo " No list a the moment !";
}
if (!($modx->db->connect(’$dbname.$tblname’))){ ---------------`to ’
echo " No list a the moment !";
}
if (!($modx->db->connect($dbname.$tblname))){
echo " No list a the moment !";
}
if (!(@$modx->db->connect(’127.0.0.1’, ’$dbname’, ’$user’, ’$pass’, true))){
echo " No list a the moment !";
}
if (!@$modx->db->connect(’127.0.0.1’, ’$dbname’, ’$user’, ’$pass’, true)){
echo " No list a the moment !";
}
what am I doing wrong?
Thanks Lisa