News-UDT for FormBuilder

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
RafaelCzernek
Forum Members
Forum Members
Posts: 13
Joined: Thu Sep 06, 2012 7:45 am

News-UDT for FormBuilder

Post by RafaelCzernek »

Hello,

i built an UDT with which i get the News Title and Content Text of an News Artikel by an ID.

Code: Select all

mysql_connect("host","username","password");
mysql_select_db("db");

if ($_GET['booking_id'] == $_GET['booking_id']) {
  $abfrage = "SELECT * FROM cms_module_news a, cms_module_news_fieldvals b WHERE a.news_id=".$_GET['booking_id']." AND b.news_id=".$_GET['booking_id']." AND a.news_id=b.news_id";
  $ergebnis = mysql_query($abfrage);

  if (mysql_num_rows($ergebnis)) {
    while($row = mysql_fetch_object($ergebnis)) {
      echo "<strong>$row->news_title</strong>";
      echo "<p>$row->news_data</p>";
      echo "Bild: $row->value";
    }
  }
  else {
  $abfrage2 = "SELECT * FROM cms_module_news WHERE NOT EXISTS (SELECT * FROM cms_module_news_fieldvals WHERE cms_module_news_fieldvals.news_id=cms_module_news.news_id) AND news_id=".$_GET['booking_id']."";
$ergebnis2 = mysql_query($abfrage2);

  while($row = mysql_fetch_object($ergebnis2)) {
    echo "<strong>$row->news_title</strong>";
    echo "<p>$row->news_data</p>";
 }
}
}
everthing works fine but if i change the mysql_connect and mysql_select_db with $gCms = cmsms(); and $db =& $gCms->GetDb(); it doesnt work.

what did i do wrong?
RafaelCzernek
Forum Members
Forum Members
Posts: 13
Joined: Thu Sep 06, 2012 7:45 am

Re: News-UDT for FormBuilder

Post by RafaelCzernek »

Here is the solution:

Code: Select all

$db = cmsms()->GetDb();
$config = cmsms()->GetConfig();

if ($_GET['booking_id'] == $_GET['booking_id']) {
	$query_1 = "SELECT * FROM cms_module_news a, cms_module_news_fieldvals b WHERE a.news_id=".$_GET['booking_id']." AND b.news_id=".$_GET['booking_id']." AND a.news_id=b.news_id AND news_category_id=2";
	$result_1 = $db->Execute($query_1);

	$query_2 = "SELECT * FROM cms_module_news WHERE NOT EXISTS (SELECT * FROM cms_module_news_fieldvals WHERE cms_module_news_fieldvals.news_id=cms_module_news.news_id) AND news_id=".$_GET['booking_id']."  AND news_category_id=2";
	$result_2 = $db->Execute($query_2);

	if (($result_1->RecordCount() > 0) || ($result_2->RecordCount() > 0)) {
		while($row = $result_1->FetchRow()) {
			echo "<h1>{$row['news_title']}</h1>";
			echo "<p>{$row['news_data']}</p>";
			echo "Bild: ".$config["root_url"]."/uploads/news/id{$row['news_id']}/{$row['value']}";
			echo "<hr />";
		}
	}
	else {
		header("Location: ../error404");
	}

	if ($result_2->RecordCount() > 0) {
		while($row = $result_2->FetchRow()) {
			echo "{$row['news_title']}";
			echo "<p>{$row['news_data']}</p>";
		}
	}
}
Post Reply

Return to “Modules/Add-Ons”