Page 1 of 1

Add recordset with CMS made simple

Posted: Thu Apr 02, 2009 9:11 am
by zoeleon
Hi, i've a problem with my page. I would like to connect a sql DB. It a success but I've 2 problems :

1 : The page show only the result of the SQL request and note all the page with menu, css, design

2 : the pictures  not displayed, it's show, a blank picture with "image not found".

Here, my php code :

Code: Select all

{php} require_once('../Connections/nopixel_bd.php');

require_once('../includes/tng/tNG.inc.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_nopixel_bd, $nopixel_bd);
$query_Recordset1 = "SELECT * FROM clients ORDER BY `date` DESC";
$Recordset1 = mysql_query($query_Recordset1, $nopixel_bd) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

// Show Dynamic Thumbnail
$objDynamicThumb1 = new tNG_DynamicThumbnail("", "KT_thumbnail1");
$objDynamicThumb1->setFolder("../imgupload/");
$objDynamicThumb1->setRenameRule("{Recordset1.image_index}");
$objDynamicThumb1->setResize(150, 101, true);
$objDynamicThumb1->setWatermark(false);
{/php}
<table border="0">
<tr>
{php}
do { // horizontal looper version 3
{/php}
<td><table width="285" border="0" cellspacing="3" cellpadding="2">
<tr>
<td width="150"><div align="center"></div></td>
<td width="120"> </td>
</tr>
<tr>
<td width="150"><a href="realisations_detail.php?id_client={php} echo $row_Recordset1['id']; {/php}"><img src="../{php} echo $objDynamicThumb1->Execute(); {/php}" alt="Vignette" border="0" /></a></td>
<td width="120" valign="top"><div align="left">{php}echo $row_Recordset1['nom'];{/php}<br />
{php} echo $row_Recordset1['description'];{/php}<br />
</div></td>
</tr>
</table></td>
{php}$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (!isset($nested_Recordset1)) {
$nested_Recordset1= 1;
}
if (isset($row_Recordset1) && is_array($row_Recordset1) && $nested_Recordset1++ % 3==0) {
echo "</tr><tr>";
}
} while ($row_Recordset1); //end horizontal looper version 3
{/php}
</tr>
</table>
{php}
mysql_free_result($Recordset1);
{/php}

I hope you understand my problem.-

Thanks for your help

Re: Add recordset with CMS made simple

Posted: Thu Apr 02, 2009 9:25 am
by alby
zoeleon wrote: Hi, i've a problem with my page. I would like to connect a sql DB. It a success but I've 2 problems :
My advice is: build a UDT and not use php in template

Alby

Re: Add recordset with CMS made simple

Posted: Thu Apr 02, 2009 9:42 am
by zoeleon
So, i'll try, but the error is now :

Code: Select all

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in D:\www\Nopixel\cms\lib\content.functions.php(857) : eval()'d code on line 30

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\www\Nopixel\cms\lib\content.functions.php(857) : eval()'d code on line 32
I do 4 UDT

1({connect}) : connect to the base :

Code: Select all

 require_once('../Connections/nopixel_bd.php');
require_once('../includes/tng/tNG.inc.php');
2({connect1}) :  My Sql request :

Code: Select all

mysql_select_db($database_nopixel_bd, $nopixel_bd);
$query_Recordset1 = "SELECT * FROM clients ORDER BY `date` DESC";
$Recordset1 = mysql_query($query_Recordset1, $nopixel_bd) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

// Show Dynamic Thumbnail
$objDynamicThumb1 = new tNG_DynamicThumbnail("", "KT_thumbnail1");
$objDynamicThumb1->setFolder("../imgupload/");
$objDynamicThumb1->setRenameRule("{Recordset1.image_index}");
$objDynamicThumb1->setResize(150, 101, true);
$objDynamicThumb1->setWatermark(false);
3({connect2})  : Display picture and descripiton

Code: Select all

echo $objDynamicThumb1->Execute(); 
echo $row_Recordset1['description'];
And 4({connect4})  : The end of recordset

Code: Select all

mysql_free_result($Recordset1);
And after into the page, in Metadonnee, i write :

{connect}
{connect1}
{connect2}
{connect3}

Is it wrong?

Re: Add recordset with CMS made simple

Posted: Thu Apr 02, 2009 1:09 pm
by Ted
1. I probably wouldn't use mysql functions directory.  It's probably safer to create a 2nd connection using the adodb library that CMSMS uses.  Chances are there's a weird conflict somewhere with either your code or adodb not using a handle correctly -- and php just falls apart at that point and doesn't remember what database connection is for what.

For the error you posted above, each UDT is a separate function when compiled, so you're having a scope issue.  Just make it one UDT to get around that.

2. You can't use relative paths in files.  You never know where the code is actually going to run -- in this case, pwd() would probably return lib/classes, but if it's a template, it would be somewhere in lib/smarty.  Use absolute paths and it should find your files just fine.