Jump to content

Form problems


unplugged_web

Recommended Posts

I wonder if somebody could help me please. I have a form that I would like to say "Sorry we did not find any results matching your search. Please try again." if no results are found, but I don't know how to do that. Sorry if it's a dumb question :) , but I've spent three days trying to figure it out and I can't. I also want to have a next and previous button for the different category's you click on.The code for the form is

<table border="0" width="100%" cellspacing="0" cellpadding="6"><tr>  <td width="180" valign=top style="border-right: 1px dotted #000000;"><table border="0" width=93% cellspacing="0" cellpadding="0"> <tr><td width="100%" style="padding-left:10px;" height="26" class=light><div class=header_small>{l_navigation}</div></td></tr><tr><td width="100%"> </td></tr><!-- begin_cats --><!-- begin_cat --><tr><td width="100%" style="padding-left: 3px; padding-bottom: 2px;"><!-- begin_cat_other --> <a href="{url_main}news.php?cat={id}" style="text-decoration: none;">{title_cat}</a><!-- end_cat_other --><!-- begin_cat_this --> <a href="{url_main}news.php?cat={id}" style="text-decoration: none; color: #fff" class=light>{title_cat}</a><!-- end_cat_this --></td></tr><!-- end_cat --><!-- begin_cat_news --><tr><td width="100%" style="padding-left: 3px; padding-bottom: 2px;"> <a href="{url_main}news.php?view={id}" style="text-decoration: none;">{title_news}</a></td></tr><!-- end_cat_news --><!-- end_cats --><td width="100%"> </td></tr><tr><td width="100%" style="padding-left:10px;" height="26" class=light><div class="header_small">{l_quick_search}</div></td></tr><tr><td width="100%"></td></tr><tr><form method="post" action="{url_page}"><td width="100%" style="padding-left: 3px; padding-bottom: 0px;"> <br><input type="text" name="keyword" style="width: 165px; margin-bottom: 2px;"><br /><input type="submit" style="width: 170px;" class="button" title="{l_search}" value="{l_search}"></td></form></tr><tr><td width="100%"> </td></tr></table>  </td>  <td width="520" valign="top" style="padding-left:10px;"><table border="0" width="453" cellspacing="1" cellpadding="3"><tr><td width="441">	<!-- begin_news -->		<!-- begin_news_item -->			<div  style="margin-bootom: 20px;">				<div class=header_small><a href="{url_page}?view={id}">{title}</a></div>				<div style="width: 100%;" align="right"><b>{day}{dt}</b></div>				<br>				{news_short}<br>			</div>		<!-- end_news_item -->		<!-- begin_news_pages -->			<div align="center" style=" width: 280px;">				<!-- begin_news_prev_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_prev}</a>  |  <!-- end_news_prev_page -->				<!-- begin_news_prev_page_off --><b>{l_prev}</b>  |  <!-- end_news_prev_page_off -->				<!-- begin_news_first_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_page_1}</a> <!-- end_news_first_page -->				<!-- begin_news_prev_pages --><a href="{url_page}?offset={offset}{params}" class="link"><<</a> <!-- end_news_prev_pages -->				<!-- begin_news_page -->					<!-- begin_news_link_page --><a href="{url_page}?offset={offset}{params}" class="link">{page}</a> <!-- end_news_link_page -->					<!-- begin_news_this_page --><b>{page}</b><!-- end_news_this_page -->				<!-- end_news_page -->				<!-- begin_news_next_pages --><a href="{url_page}?offset={offset}{params}" class="link">>></a> <!-- end_news_next_pages -->				<!-- begin_news_last_page --><b>{l_of}</b> <a href="{url_page}?offset={offset}{params}" class="link">{num_pages}</a> <!-- end_news_last_page -->				<!-- begin_news_next_page -->  |  <a href="{url_page}?offset={offset}{params}" class="link">{l_next}</a><!-- end_news_next_page -->				<!-- begin_news_next_page_off -->  |  <b>{l_next}</b><!-- end_news_next_page_off -->			</div>		<!-- end_news_pages -->	<!-- end_news -->	<!-- begin_news_view -->		<div  style="">			<div class=header_small>{title}</div>			<div style="width: 100%;" align="right"><b>{day}{dt}</b></div>			<br>			{news_long}			<br><br>		</div>		<div align="center" style=" width: 280px;">				<!-- begin_news_prev_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_prev}</a>  |  <!-- end_news_prev_page -->				<!-- begin_news_prev_page_off --><b>{l_prev}</b>  |  <!-- end_news_prev_page_off -->				<!-- begin_news_first_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_page_1}</a> <!-- end_news_first_page -->				<!-- begin_news_prev_pages --><a href="{url_page}?offset={offset}{params}" class="link"><<</a> <!-- end_news_prev_pages -->				<!-- begin_news_page -->					<!-- begin_news_link_page --><a href="{url_page}?offset={offset}{params}" class="link">{page}</a> <!-- end_news_link_page -->					<!-- begin_news_this_page --><b>{page}</b><!-- end_news_this_page -->				<!-- end_news_page -->				<!-- begin_news_next_pages --><a href="{url_page}?offset={offset}{params}" class="link">>></a> <!-- end_news_next_pages -->				<!-- begin_news_last_page --><b>{l_of}</b> <a href="{url_page}?offset={offset}{params}" class="link">{num_pages}</a> <!-- end_news_last_page -->				<!-- begin_news_next_page -->  |  <a href="{url_page}?offset={offset}{params}" class="link">{l_next}</a><!-- end_news_next_page -->				<!-- begin_news_next_page_off -->  |  <b>{l_next}</b><!-- end_news_next_page_off -->			</div>	<!-- end_news_view --></td></tr></table> </td>	  </tr>	</table>

while to code in the php file is

include("./_include/core/main_start.php");class CNews extends CHtmlList{	var $m_on_page = 5;			function CNews($name, $html_path)	{		$this->CHtmlList($name, $html_path);			}	function init()	{		parent::init();		$this->m_sql_count = "SELECT COUNT(n.id) FROM news AS n " . $this->m_sql_from_add . "";		$this->m_sql = "			SELECT n.id, n.title, n.news_short, n.news_long, n.dt, n.cat, n.visible			FROM news AS n			" . $this->m_sql_from_add . "		";		$this->m_field['id'] = array("id", null);		$this->m_field['title'] = array("title", null);		$this->m_field['news_short'] = array("news_short", null);		$this->m_field['news_long'] = array("news_long", null);		$this->m_field['cat'] = array("cat", null);		$this->m_field['dt'] = array("dt", null);		$this->m_field['day'] = array("day", null);		$this->m_sql_order = " dt DESC ";	}	function parseBlock(&$html)	{		parent::parseBlock($html);	}		function onItem(&$html, $row, $i, $last)	{		$this->m_field['dt'][1] = date("/m/y", $row['dt']);		$this->m_field['day'][1] = date("d", $row['dt']);		$this->m_field['news_short'][1] = nl2br($row['news_short']);		$this->m_field['news_long'][1] = nl2br($row['news_long']);		$this->m_field['cat'][1] = DB::result("SELECT title FROM news_cats WHERE id=" . $row['cat'] . "", 0, 2);		if ($this->m_field['cat'][1] == "")		{			$this->m_field['cat'][1] = " ";		}	}	}class CCats extends CHtmlBlock{	function CCats($name, $html_path)	{		$this->CHtmlBlock($name, $html_path);	}	function parseBlock(&$html)	{		DB::query("SELECT id, title FROM news_cats ORDER BY id");				while ($row = DB::fetch_row())		{			if (get_param("cat", "") == $row['id'])			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_this", false);				$html->setblockvar("cat_other", "");			}			else			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_other", false);				$html->setblockvar("cat_this", "");			}			$html->parse("cat", true);		}				DB::query("SELECT id, title, news_short, dt, cat, visible FROM news WHERE visible='Y' AND cat=0 ORDER BY id");		$i = 1;		while ($row = DB::fetch_row())		{			$row['offset'] = $i;			foreach ($row as $k => $v)			{				if ($k == "title")				{					$html->setvar("title_news", $v);				}				else				{					$html->setvar($k, $v);				}			}						$html->parse("cat_news", true);			$i++;		}				parent::parseBlock($html);	}}$page = new CHtmlBlock("", $g['tmpl']['dir_tmpl_main'] . "news.html");$header = new CHeader("header", $g['tmpl']['dir_tmpl_main'] . "_header.html");$page->add($header);$footer = new CFooter("footer", $g['tmpl']['dir_tmpl_main'] . "_footer.html");$page->add($footer);$cats = new CCats("cats", null);$page->add($cats);$cat = get_param("cat", 1);$view = get_param("view", "");$key = get_param("keyword", "");if ($view != ""){	$news = new CNews("news_view", null);	$where = "";	$where .= " AND id=" . to_sql($view, "Number") . "";}elseif ($key != ""){	$news = new CNews("news", null);	$where = "";	if ($key != "")	{		$where .= " AND title LIKE '%" . to_sql($key, "Plain") . "%' OR news_short LIKE '%" . to_sql($key, "Plain") . "%' or news_long LIKE '%" . to_sql($key, "Plain") . "%'";	}	#$where .= " AND cat!=0";}else{	$news = new CNews("news", null);	$where = "";	$cat = get_param("cat", 1);	$where .= " AND cat=" . to_sql($cat, "Number") . "";}$news->m_sql_where = " visible='Y' " . $where;$page->add($news);$users_ims = new CIms("ims", $g['tmpl']['dir_tmpl_main'] . "_ims.html");$page->add($users_ims);include("./_include/core/main_close.php");?>

I don't know if it helps, but you can see the page hereThanks

Link to comment
Share on other sites

Wow talk about custom classes! Oh well, by whatever method your database class supports get the number of rows (the mysql function is mysql_num_rows($result)) and if it equals zero you can echo the message.You could even put a method for that in the object.

Link to comment
Share on other sites

Wow talk about custom classes! Oh well, by whatever method your database class supports get the number of rows (the mysql function is mysql_num_rows($result)) and if it equals zero you can echo the message.You could even put a method for that in the object.
Thanks, so if I add
 if (mysql_num_rows($result) = 0){	echo="Sorry we did not find any results matching your search. Please try again."}

then it'll work? Also where abouts do I put the code?

Link to comment
Share on other sites

Thanks, so if I add
 if (mysql_num_rows($result) = 0){	echo="Sorry we did not find any results matching your search. Please try again."}

then it'll work? Also where abouts do I put the code?

The syntax of the code is wrong. You have to fix this:if (mysql_num_rows($result) == 0)And this:echo"Sorry we did not find any results matching your search. Please try again.";You're supposed to put the code wherever you're going to output the database data.
if (mysql_num_rows($result) == 0) {	echo "Sorry we did not find any results matching your search. Please try again.";} else {  // Follow the normal output routine}

Link to comment
Share on other sites

Sorry, I added that to just below the DB::query line, but nothing changed

function parseBlock(&$html)	{		DB::query("SELECT id, title FROM news_cats ORDER BY id");				while ($row = DB::fetch_row())		{		if (mysql_num_rows($result) == 0) {	echo "Sorry we did not find any results matching your search. Please try again.";} elseif (get_param("cat", "") == $row['id'])			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_this", false);				$html->setblockvar("cat_other", "");			}			else			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_other", false);				$html->setblockvar("cat_this", "");			}			$html->parse("cat", true);		}				DB::query("SELECT id, title, news_short, dt, cat, visible FROM news WHERE visible='Y' AND cat=0 ORDER BY id");		$i = 1;		while ($row = DB::fetch_row())		{			$row['offset'] = $i;			foreach ($row as $k => $v)			{				if ($k == "title")				{					$html->setvar("title_news", $v);				}				else				{					$html->setvar($k, $v);				}			}						$html->parse("cat_news", true);			$i++;		}				parent::parseBlock($html);	}}

Link to comment
Share on other sites

You shouldn't echo to send output, this is a template class that processes the HTML for you. That means you need to have the message inside the template and you need to tell the template engine whether or not to show that part. So you would add something like this to the template wherever you want it to show up:

		<!-- begin_cat_no_results -->			<div>Your search did not return any results</div>		<!-- end_cat_no_results -->

The parseBlock function would show that message like this:$html->parse("cat_no_results", false);$html->setblockvar("cat_no_results", "");$html->parse("cat", false);I'm not sure what IF statement to use to test for that though unless you can post the source for the DB class. It probably has something to determine how many results there are.

Link to comment
Share on other sites

I changed the code to

class CCats extends CHtmlBlock{	function CCats($name, $html_path)	{		$this->CHtmlBlock($name, $html_path);	}	function parseBlock(&$html)	{		DB::query("SELECT id, title FROM news_cats ORDER BY id");				while ($row = DB::fetch_row())		{			if (get_param("cat", "") == $row['id'])			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_this", false);				$html->setblockvar("cat_other", "");			}			else			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_other", false);				$html->setblockvar("cat_this", "");			}						$html->parse("cat", true);		}while ($row = DB::fetch_row())		{			if (get_param("cat", "") == $row['id'])			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_no_results", false);				$html->setblockvar("cat_no_results", "");			}				$html->parse("cat", false);		}

but it doesn't work. I don't know if I put it in the wrong place or not

Link to comment
Share on other sites

If you're not 100% sure then don't put it anywhere, instead of randomly trying things out you need to understand where it goes. Trial and error only gets you so far. It goes outside of the while loop, not inside it. The while loop loops through all of the records. If there aren't any records it won't enter the while loop at all. So putting it inside the while loop doesn't have any effect (or, it will show the message every time it prints a category). So it goes in an if statement outside of the while loop (probably before would make sense), but I can't tell you what the if statement should say until I see the DB class. The if statement needs to check how many records there are but I don't know the way to do that with the custom class, I don't have the code for it. I don't know where it's defined, I'm not sure what you're working with.

Link to comment
Share on other sites

This is the function

class CCats extends CHtmlBlock{	function CCats($name, $html_path)	{		$this->CHtmlBlock($name, $html_path);	}	function parseBlock(&$html)	{		DB::query("SELECT id, title FROM news_cats ORDER BY id");				while ($row = DB::fetch_row())		{			if (get_param("cat", "") == $row['id'])			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_this", false);				$html->setblockvar("cat_other", "");			}			else			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_other", false);				$html->setblockvar("cat_this", "");			}			$html->parse("cat", true);		}

but I can't find the class I've tried searching for CCats, class and function, but I don't seem to be able to find it

Link to comment
Share on other sites

I think that this might be the database class:

<?php$DB_res = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);$DB_conn = 0;$DB_debug = false;$DB_timer = 0;$DB_sqls = "";class DB{	function connect()	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		$host = $g['db']['host'];		$db = $g['db']['db'];		$user = $g['db']['user'];		$pass = $g['db']['password'];		if ($DB_debug) $DB_timer = ($DB_timer + time() + microtime());		$DB_conn = mysql_connect($host, $user, $pass);		if (!$DB_conn)		{			trigger_error("Can't connect to MySql: " . mysql_error());		}		mysql_select_db($db) or trigger_error("Can't select database: " . mysql_error());		#mysql_query("SET NAMES utf8") or trigger_error("Can't execute query: " . mysql_error());		#if (isset($g['character_set']) and $g['character_set'] == "Y")		{			mysql_query("SET NAMES 'utf8'");			if (mysql_query("SET character SET 'utf8'"))			{				#mysql_query("SET character SET 'utf8'") or trigger_error("Can't execute query: " . mysql_error());				mysql_query('SET character_set_client = utf8') or trigger_error("Can't execute query: " . mysql_error());				mysql_query('SET character_set_results = utf8') or trigger_error("Can't execute query: " . mysql_error());				mysql_query('SET character_set_connection = utf8') or trigger_error("Can't execute query: " . mysql_error());				mysql_query("SET SESSION collation_connection ='utf8_bin';") or trigger_error("Can't execute query: " . mysql_error());			}		}		if ($DB_debug)		{			$DB_timer = - ($DB_timer - time() - microtime());			$DB_sqls .= "Connection time: " . $DB_timer . "<br />";		}	}	function close()	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		if ($DB_debug) $DB_timer_cur = time() + microtime();		if ($DB_conn)		{			mysql_close($DB_conn);			$DB_conn = 0;		}		if ($DB_debug)		{			$DB_timer_cur = - ($DB_timer_cur - time() - microtime());			$DB_timer = $DB_timer + $DB_timer_cur;			$DB_sqls .= "Disconnection time: " . $DB_timer_cur . "<br />";			$DB_sqls .= "Total time: " . $DB_timer . "<br />";			echo $DB_sqls;		}	}	function execute($sql, $error = true)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		if ($DB_debug) $DB_timer_cur = time() + microtime();		if (!($r = mysql_query($sql, $DB_conn)) and $error)		{			trigger_error("Can't execute query: " . mysql_error() . "\r\n" . $sql);		}		if ($DB_debug)		{			$DB_timer_cur = - ($DB_timer_cur - time() - microtime());			$DB_timer = $DB_timer + $DB_timer_cur;			$DB_sqls .= "Sql query: " . $sql . "<br />";			$DB_sqls .= "Sql execute time: " . $DB_timer_cur . "<br />";		}		if ($r)		{			return 1;		}	}	function query($sql, $r = 0)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		if ($DB_debug) $DB_timer_cur = time() + microtime();		if ($DB_res[$r])		{			mysql_free_result($DB_res[$r]);			$DB_res[$r] = 0;		}		$DB_res[$r] = mysql_query($sql, $DB_conn) or trigger_error("Can't execute query: " . mysql_error() . "\r\n" . $sql);		if ($DB_debug)		{			$DB_timer_cur = - ($DB_timer_cur - time() - microtime());			$DB_timer = $DB_timer + $DB_timer_cur;			$DB_sqls .= "Sql query: " . $sql . "<br />";			$DB_sqls .= "Sql execute time: " . $DB_timer_cur . "<br />";		}		if ($DB_res[$r])		{			return 1;		}		else		{			return 0;		}	}	function fetch_row($r = 0)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		if (!$DB_res[$r])		{			return 0;		}		$ret = mysql_fetch_array($DB_res[$r]);		if (!$ret)		{			mysql_free_result($DB_res[$r]);			$DB_res[$r] = 0;		}		return $ret;	}	function affected_rows()	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		return mysql_affected_rows($DB_conn);	}	function num_rows($r = 0)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		if (!$DB_res[$r])		{			return 0;		}		return mysql_num_rows($DB_res[$r]);	}	function free_result($r = 0)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		if ($DB_res[$r])		{			mysql_free_result($DB_res[$r]);			$DB_res[$r] = 0;		}	}	function insert_id()	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		return mysql_insert_id($DB_conn);	}	function result($sql, $i = 0, $r = 0)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		$ret = 0;		if (DB::query($sql, $r))		{			if ($row = DB::fetch_row($r))			{				$ret = $row[$i];				mysql_free_result($DB_res[$r]);				$DB_res[$r] = 0;			}		}		return $ret;	}	function result_cache($name, $mins, $sql, $i = 0, $r = 0)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		$cache = cache($name, $mins);		if ($cache === false)		{			$ret = DB::result($sql, $i, $r);			cache_update($name, $ret);		}		else $ret = $cache;		return $ret;	}	function db_options($sql, $selected = "", $r = 0)	{		global $g;		global $l;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		$ret = "";		if ($selected == "last_option")		{			if (DB::query($sql, $r))			{				$j = DB::num_rows($r);				$i = 0;				while ($row = DB::fetch_row($r))				{					$i++;					if ($i == $j)					{						$ret .= "<option value=\"" . $row[0] . "\" selected=\"selected\">" . (isset($l['all'][to_php_alfabet($row[1])]) ? $l['all'][to_php_alfabet($row[1])] : $row[1]) . "</option>\n";					}					else					{						$ret .= "<option value=\"" . $row[0] . "\">" . (isset($l['all'][to_php_alfabet($row[1])]) ? $l['all'][to_php_alfabet($row[1])] : $row[1]) . "</option>\n";					}				}				DB::free_result($r);			}		}		elseif ($selected == "first")		{			if (DB::query($sql, $r))			{				$j = DB::num_rows($r);				$i = 0;				while ($row = DB::fetch_row($r))				{					$i++;					if ($i == 1)					{						$ret .= "<option value=\"" . $row[0] . "\" selected=\"selected\">" . (isset($l['all'][to_php_alfabet($row[1])]) ? $l['all'][to_php_alfabet($row[1])] : $row[1]) . "</option>\n";					}					else					{						$ret .= "<option value=\"" . $row[0] . "\">" . (isset($l['all'][to_php_alfabet($row[1])]) ? $l['all'][to_php_alfabet($row[1])] : $row[1]) . "</option>\n";					}				}				DB::free_result($r);			}		}		else		{			if (DB::query($sql, $r))			{				while ($row = DB::fetch_row($r))				{					$ret .= "<option value=\"" . $row[0] . "\"" . (($row[0] == $selected) ? " selected=\"selected\"" : "") . ">" . (isset($l['all'][to_php_alfabet($row[1])]) ? $l['all'][to_php_alfabet($row[1])] : $row[1]) . "</option>\n";				}				DB::free_result($r);			}		}		return $ret;	}	function show_table($sql, $table, $limit = 0, $from = 0, $r = 0)	{		global $g;		global $DB_conn;		global $DB_res;		global $DB_debug;		global $DB_timer;		global $DB_sqls;		$html = "";		$first_string = 1;		if ($from != 0) $from = "," . $from . "";		if ($limit == 0) $$limit = "";		DB::query("SELECT * FROM " . $table . " LIMIT " . $limit . $from . "", $r);		$html .= "<table border=1 cellpacing=5 cellpadding=5>";		while ($row = DB::fetch_row($r))		{			if ($first_string == 1)			{				$html .= "<tr>";				foreach ($row as $k => $v)				{					if (!is_int($k))					{						$html .= "<td>";						$html .= "<b>" . $k . "</b>";						$html .= "</td>";					}				}				$html .= "</tr>";				$first_string = 0;			}			$html .= "<tr>";			foreach ($row as $k => $v)			{				if (!is_int($k))				{					$html .= "<td>";					$html .= nl2br($v);					$html .= "</td>";				}			}			$html .= "</tr>";		}		$html .= "</table>";		return $html;	}}?>

Link to comment
Share on other sites

Perfect it has an inbuilt function.

if (DB::num_rows() == 0) ...

Link to comment
Share on other sites

That's sort of a strange way to write a class, to use global variables for everything instead of class variables.You can add the if statement into the parseBlock function:

		DB::query("SELECT id, title FROM news_cats ORDER BY id");		if (DB::num_rows() == 0)		{		  $html->parse("cat_no_results", false);		  $html->setblockvar("cat_no_results", "");		  $html->parse("cat", false);		}				while ($row = DB::fetch_row())

Link to comment
Share on other sites

That's sort of a strange way to write a class, to use global variables for everything instead of class variables.You can add the if statement into the parseBlock function:
		DB::query("SELECT id, title FROM news_cats ORDER BY id");		if (DB::num_rows() == 0)		{		  $html->parse("cat_no_results", false);		  $html->setblockvar("cat_no_results", "");		  $html->parse("cat", false);		}				while ($row = DB::fetch_row())

Thanks
Link to comment
Share on other sites

Thanks
Sorry I'm back again. I changed the php file to:
function parseBlock(&$html)	{		DB::query("SELECT id, title FROM news_cats ORDER BY id");		if (DB::num_rows() == 0)		{		  $html->parse("cat_no_results", false);		  $html->setblockvar("cat_no_results", "");		  $html->parse("cat", false);		}				while ($row = DB::fetch_row())		{			if (get_param("cat", "") == $row['id'])			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_this", false);				$html->setblockvar("cat_other", "");			}			else			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_other", false);				$html->setblockvar("cat_this", "");			}			$html->parse("cat", true);		}

and added:

<div align="center" style=" width: 280px;">				<!-- begin_news_prev_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_prev}</a>  |  <!-- end_news_prev_page -->				<!-- begin_news_prev_page_off --><b>{l_prev}</b>  |  <!-- end_news_prev_page_off -->				<!-- begin_news_first_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_page_1}</a> <!-- end_news_first_page -->				<!-- begin_news_prev_pages --><a href="{url_page}?offset={offset}{params}" class="link"><<</a> <!-- end_news_prev_pages -->				<!-- begin_news_page -->					<!-- begin_news_link_page --><a href="{url_page}?offset={offset}{params}" class="link">{page}</a> <!-- end_news_link_page -->					<!-- begin_news_this_page --><b>{page}</b><!-- end_news_this_page -->				<!-- end_news_page -->				<!-- begin_news_next_pages --><a href="{url_page}?offset={offset}{params}" class="link">>></a> <!-- end_news_next_pages -->				<!-- begin_news_last_page --><b>{l_of}</b> <a href="{url_page}?offset={offset}{params}" class="link">{num_pages}</a> <!-- end_news_last_page -->				<!-- begin_news_next_page -->  |  <a href="{url_page}?offset={offset}{params}" class="link">{l_next}</a><!-- end_news_next_page -->				<!-- begin_news_next_page_off -->  |  <b>{l_next}</b><!-- end_news_next_page_off -->			</div>	<!-- end_news_view -->	<!-- begin_cat_no_results -->			<div>Sorry we did not find any results matching your search. Please try again.</div>		<!-- end_cat_no_results -->

to the html file, but it's still not working

Link to comment
Share on other sites

The cat_no_results block in the template file needs to be inside the cat block. There is already a block labeled <!-- begin_cat --> and cat_no_results needs to be inside there somewhere.
I added the code to the begin_news block
<table border="0" width="453" cellspacing="1" cellpadding="3"><tr><td width="441">	<!-- begin_news -->		<!-- begin_news_item -->			<div  style="margin-bootom: 20px;">				<div class=header_small><a href="{url_page}?view={id}">{title}</a></div>				<div style="width: 100%;" align="right"><b>{day}{dt}</b></div>				<br>				{news_short}<br>			</div>		<!-- end_news_item -->		<!-- begin_news_pages -->			<div align="center" style=" width: 280px;">				<!-- begin_news_prev_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_prev}</a>  |  <!-- end_news_prev_page -->				<!-- begin_news_prev_page_off --><b>{l_prev}</b>  |  <!-- end_news_prev_page_off -->				<!-- begin_news_first_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_page_1}</a> <!-- end_news_first_page -->				<!-- begin_news_prev_pages --><a href="{url_page}?offset={offset}{params}" class="link"><<</a> <!-- end_news_prev_pages -->				<!-- begin_news_page -->					<!-- begin_news_link_page --><a href="{url_page}?offset={offset}{params}" class="link">{page}</a> <!-- end_news_link_page -->					<!-- begin_news_this_page --><b>{page}</b><!-- end_news_this_page -->				<!-- end_news_page -->				<!-- begin_news_next_pages --><a href="{url_page}?offset={offset}{params}" class="link">>></a> <!-- end_news_next_pages -->				<!-- begin_news_last_page --><b>{l_of}</b> <a href="{url_page}?offset={offset}{params}" class="link">{num_pages}</a> <!-- end_news_last_page -->				<!-- begin_news_next_page -->  |  <a href="{url_page}?offset={offset}{params}" class="link">{l_next}</a><!-- end_news_next_page -->				<!-- begin_news_next_page_off -->  |  <b>{l_next}</b><!-- end_news_next_page_off -->			</div>		<!-- end_news_pages -->	<!-- end_news -->	<!-- begin_news_view -->		<div  style="">			<div class=header_small>{title}</div>			<div style="width: 100%;" align="right"><b>{day}{dt}</b></div>			<br>			{news_long}			<br><br>		</div>		<div align="center" style=" width: 280px;">				<!-- begin_news_prev_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_prev}</a>  |  <!-- end_news_prev_page -->				<!-- begin_news_prev_page_off --><b>{l_prev}</b>  |  <!-- end_news_prev_page_off -->				<!-- begin_news_first_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_page_1}</a> <!-- end_news_first_page -->				<!-- begin_news_prev_pages --><a href="{url_page}?offset={offset}{params}" class="link"><<</a> <!-- end_news_prev_pages -->				<!-- begin_news_page -->					<!-- begin_news_link_page --><a href="{url_page}?offset={offset}{params}" class="link">{page}</a> <!-- end_news_link_page -->					<!-- begin_news_this_page --><b>{page}</b><!-- end_news_this_page -->				<!-- end_news_page -->				<!-- begin_news_next_pages --><a href="{url_page}?offset={offset}{params}" class="link">>></a> <!-- end_news_next_pages -->				<!-- begin_news_last_page --><b>{l_of}</b> <a href="{url_page}?offset={offset}{params}" class="link">{num_pages}</a> <!-- end_news_last_page -->				<!-- begin_news_next_page -->  |  <a href="{url_page}?offset={offset}{params}" class="link">{l_next}</a><!-- end_news_next_page -->				<!-- begin_news_next_page_off -->  |  <b>{l_next}</b><!-- end_news_next_page_off -->			</div>	<!-- begin_cat_no_results -->			<div>Sorry we did not find any results matching your search. Please try again.</div>		<!-- end_cat_no_results -->	<!-- end_news_view --></td></tr></table>

but that didn't work. I tried adding it to the begin_cat block, but that is in the wrong place on the page, but that didn't work either

Link to comment
Share on other sites

Well, from what I can tell it needs to go in the begin_cat block because that's what we are parsing. We aren't parsing the news block at this point. It's a little difficult to tell though without the code for the template engine, but that's what I'm thinking. You might try changing a false to true, I thought that the true/false indicated if it was the last block but I'm not sure what that parameter does because I haven't seen the code that's using it. But move the template code into the cat block and try to use true instead of false.$html->parse("cat", true);

Link to comment
Share on other sites

Well, from what I can tell it needs to go in the begin_cat block because that's what we are parsing. We aren't parsing the news block at this point. It's a little difficult to tell though without the code for the template engine, but that's what I'm thinking. You might try changing a false to true, I thought that the true/false indicated if it was the last block but I'm not sure what that parameter does because I haven't seen the code that's using it. But move the template code into the cat block and try to use true instead of false.$html->parse("cat", true);
No sorry that didn't work either. The code for the php page is:
<?php/* (C) ABK-Soft Ltd., 2004-2006IMPORTANT: This is a commercial software productand any kind of using it must agree to the ABK-SoftLtd. license agreement.It can be found at http://abk-soft.com/license.docThis notice may not be removed from the source code. */include("./_include/core/main_start.php");class CNews extends CHtmlList{	var $m_on_page = 5;			function CNews($name, $html_path)	{		$this->CHtmlList($name, $html_path);			}	function init()	{		parent::init();		$this->m_sql_count = "SELECT COUNT(n.id) FROM news AS n " . $this->m_sql_from_add . "";		$this->m_sql = "			SELECT n.id, n.title, n.news_short, n.news_long, n.dt, n.cat, n.visible			FROM news AS n			" . $this->m_sql_from_add . "		";		$this->m_field['id'] = array("id", null);		$this->m_field['title'] = array("title", null);		$this->m_field['news_short'] = array("news_short", null);		$this->m_field['news_long'] = array("news_long", null);		$this->m_field['cat'] = array("cat", null);		$this->m_field['dt'] = array("dt", null);		$this->m_field['day'] = array("day", null);		$this->m_sql_order = " dt DESC ";	}	function parseBlock(&$html)	{		parent::parseBlock($html);	}		function onItem(&$html, $row, $i, $last)	{		$this->m_field['dt'][1] = date("/m/y", $row['dt']);		$this->m_field['day'][1] = date("d", $row['dt']);		$this->m_field['news_short'][1] = nl2br($row['news_short']);		$this->m_field['news_long'][1] = nl2br($row['news_long']);		$this->m_field['cat'][1] = DB::result("SELECT title FROM news_cats WHERE id=" . $row['cat'] . "", 0, 2);		if ($this->m_field['cat'][1] == "")		{			$this->m_field['cat'][1] = " ";		}	}	}class CCats extends CHtmlBlock{	function CCats($name, $html_path)	{		$this->CHtmlBlock($name, $html_path);	}	function parseBlock(&$html)	{		DB::query("SELECT id, title FROM news_cats ORDER BY id");		if (DB::num_rows() == 0)		{		  $html->parse("cat_no_results", false);		  $html->setblockvar("cat_no_results", "");		  $html->parse("cat", true);		}				while ($row = DB::fetch_row())		{			if (get_param("cat", "") == $row['id'])			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_this", false);				$html->setblockvar("cat_other", "");			}			else			{				$html->setvar("id", $row['id']);				$html->setvar("title_cat", $row['title']);				$html->parse("cat_other", false);				$html->setblockvar("cat_this", "");			}			$html->parse("cat", true);		}						DB::query("SELECT id, title, news_short, dt, cat, visible FROM news WHERE visible='Y' AND cat=0 ORDER BY id");		$i = 1;		while ($row = DB::fetch_row())		{			$row['offset'] = $i;			foreach ($row as $k => $v)			{				if ($k == "title")				{					$html->setvar("title_news", $v);				}				else				{					$html->setvar($k, $v);				}			}						$html->parse("cat_news", true);			$i++;		}				parent::parseBlock($html);	}}$page = new CHtmlBlock("", $g['tmpl']['dir_tmpl_main'] . "news.html");$header = new CHeader("header", $g['tmpl']['dir_tmpl_main'] . "_header.html");$page->add($header);$footer = new CFooter("footer", $g['tmpl']['dir_tmpl_main'] . "_footer.html");$page->add($footer);$cats = new CCats("cats", null);$page->add($cats);$cat = get_param("cat", 1);$view = get_param("view", "");$key = get_param("keyword", "");if ($view != ""){	$news = new CNews("news_view", null);	$where = "";	$where .= " AND id=" . to_sql($view, "Number") . "";}elseif ($key != ""){	$news = new CNews("news", null);	$where = "";	if ($key != "")	{		$where .= " AND title LIKE '%" . to_sql($key, "Plain") . "%' OR news_short LIKE '%" . to_sql($key, "Plain") . "%' or news_long LIKE '%" . to_sql($key, "Plain") . "%'";	}	#$where .= " AND cat!=0";}else{	$news = new CNews("news", null);	$where = "";	$cat = get_param("cat", 1);	$where .= " AND cat=" . to_sql($cat, "Number") . "";}$news->m_sql_where = " visible='Y' " . $where;$page->add($news);$users_ims = new CIms("ims", $g['tmpl']['dir_tmpl_main'] . "_ims.html");$page->add($users_ims);include("./_include/core/main_close.php");?>

and the code for the html page is:

{header}<div class="userinfo-c-wide">	<div class="userinfo smallphoto clearfix">		<input style="width: 170px;" type="button" class="button" onclick="location='{url_main}';" title="Home" value="Home">	<input style="width: 170px;" type="button" class="button" onclick="location='{url_main}news.php';" title="Site Info" value="Site Info">	<input style="width: 170px;" type="button" class="button" onclick="location='{url_main}help.php';" title="Help" value="Help">	<input style="width: 170px;" type="button" class="button" onclick="location='{url_main}contact.php';" title="Contact us" value="Contact us"><table border="0" width="100%" cellspacing="0" cellpadding="0" class="content_bgrnd"  style="padding-left: 20px; padding-top: 5px;"><tr>		<td height="10"> 				</td></tr><tr>		<td class=banner >		<div class="header_big"><img src="./_themes/main/new/images/info.png" style="behavior: url('./_server/design/pngbehavior.htc');" align="absmiddle" alt="" width=48 height=48> Site Info</div>		</td></tr><tr><td>  </center> <table border="0" width="100%" cellspacing="0" cellpadding="6"><tr>  <td width="180" valign=top style="border-right: 1px dotted #000000;"><table border="0" width=93% cellspacing="0" cellpadding="0"> <tr><td width="100%" style="padding-left:10px;" height="26" class=light><div class=header_small>{l_navigation}</div></td></tr><tr><td width="100%"> </td></tr><!-- begin_cats --><!-- begin_cat --><tr><td width="100%" style="padding-left: 3px; padding-bottom: 2px;"><!-- begin_cat_other --> <a href="{url_main}news.php?cat={id}" style="text-decoration: none;">{title_cat}</a><!-- end_cat_other --><!-- begin_cat_this --> <a href="{url_main}news.php?cat={id}" style="text-decoration: none; color: #fff" class=light>{title_cat}</a><!-- end_cat_this --></td></tr><!-- end_cat --><!-- begin_cat_news --><tr><td width="100%" style="padding-left: 3px; padding-bottom: 2px;"> <a href="{url_main}news.php?view={id}" style="text-decoration: none;">{title_news}</a></td></tr><!-- end_cat_news --><!-- end_cats --><td width="100%"> </td></tr><tr><td width="100%" style="padding-left:10px;" height="26" class=light><div class="header_small">{l_quick_search}</div></td></tr><tr><td width="100%"></td></tr><tr><form method="post" action="{url_page}"><td width="100%" style="padding-left: 3px; padding-bottom: 0px;"> <br><input type="text" name="keyword" style="width: 165px; margin-bottom: 2px;"><br /><input type="submit" style="width: 170px;" class="button" title="{l_search}" value="{l_search}"></td></form></tr><tr><td width="100%"> </td></tr></table>  </td>  <td width="520" valign="top" style="padding-left:10px;"><table border="0" width="453" cellspacing="1" cellpadding="3"><tr><td width="441">	<!-- begin_news -->		<!-- begin_news_item -->			<div  style="margin-bootom: 20px;">				<div class=header_small><a href="{url_page}?view={id}">{title}</a></div>				<div style="width: 100%;" align="right"><b>{day}{dt}</b></div>				<br>				{news_short}<br>			</div>		<!-- end_news_item -->		<!-- begin_news_pages -->			<div align="center" style=" width: 280px;">				<!-- begin_news_prev_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_prev}</a>  |  <!-- end_news_prev_page -->				<!-- begin_news_prev_page_off --><b>{l_prev}</b>  |  <!-- end_news_prev_page_off -->				<!-- begin_news_first_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_page_1}</a> <!-- end_news_first_page -->				<!-- begin_news_prev_pages --><a href="{url_page}?offset={offset}{params}" class="link"><<</a> <!-- end_news_prev_pages -->				<!-- begin_news_page -->					<!-- begin_news_link_page --><a href="{url_page}?offset={offset}{params}" class="link">{page}</a> <!-- end_news_link_page -->					<!-- begin_news_this_page --><b>{page}</b><!-- end_news_this_page -->				<!-- end_news_page -->				<!-- begin_news_next_pages --><a href="{url_page}?offset={offset}{params}" class="link">>></a> <!-- end_news_next_pages -->				<!-- begin_news_last_page --><b>{l_of}</b> <a href="{url_page}?offset={offset}{params}" class="link">{num_pages}</a> <!-- end_news_last_page -->				<!-- begin_news_next_page -->  |  <a href="{url_page}?offset={offset}{params}" class="link">{l_next}</a><!-- end_news_next_page -->				<!-- begin_news_next_page_off -->  |  <b>{l_next}</b><!-- end_news_next_page_off -->			</div>		<!-- end_news_pages -->	<!-- end_news -->	<!-- begin_news_view -->		<div  style="">			<div class=header_small>{title}</div>			<div style="width: 100%;" align="right"><b>{day}{dt}</b></div>			<br>			{news_long}			<br><br>		</div>		<div align="center" style=" width: 280px;">				<!-- begin_news_prev_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_prev}</a>  |  <!-- end_news_prev_page -->				<!-- begin_news_prev_page_off --><b>{l_prev}</b>  |  <!-- end_news_prev_page_off -->				<!-- begin_news_first_page --><a href="{url_page}?offset={offset}{params}" class="link">{l_page_1}</a> <!-- end_news_first_page -->				<!-- begin_news_prev_pages --><a href="{url_page}?offset={offset}{params}" class="link"><<</a> <!-- end_news_prev_pages -->				<!-- begin_news_page -->					<!-- begin_news_link_page --><a href="{url_page}?offset={offset}{params}" class="link">{page}</a> <!-- end_news_link_page -->					<!-- begin_news_this_page --><b>{page}</b><!-- end_news_this_page -->				<!-- end_news_page -->				<!-- begin_news_next_pages --><a href="{url_page}?offset={offset}{params}" class="link">>></a> <!-- end_news_next_pages -->				<!-- begin_news_last_page --><b>{l_of}</b> <a href="{url_page}?offset={offset}{params}" class="link">{num_pages}</a> <!-- end_news_last_page -->				<!-- begin_news_next_page -->  |  <a href="{url_page}?offset={offset}{params}" class="link">{l_next}</a><!-- end_news_next_page -->				<!-- begin_news_next_page_off -->  |  <b>{l_next}</b><!-- end_news_next_page_off -->			</div>	<!-- begin_cat_no_results -->			<div>Sorry we did not find any results matching your search. Please try again.</div>		<!-- end_cat_no_results -->	<!-- end_news_view --></td></tr></table> </td>	  </tr>	</table>	</td>  </tr></table></div><div class="userinfo-links-wide"></div></div>{footer}

Sorry to be a pain about this

Link to comment
Share on other sites

You still have the cat_no_results block in the wrong place. It needs to go in the cat block. Once it works then we can figure out how to move it where you want it, step 1 is to get it to work in the first place. It's not going to work at all if the code isn't in the right place.There's still some code missing. Look at this definition:class CCats extends CHtmlBlockIt extends the CHtmlBlock class. I don't see the code for that one. Presumably the parse method is in there somewhere.

Link to comment
Share on other sites

You still have the cat_no_results block in the wrong place. It needs to go in the cat block. Once it works then we can figure out how to move it where you want it, step 1 is to get it to work in the first place. It's not going to work at all if the code isn't in the right place.There's still some code missing. Look at this definition:class CCats extends CHtmlBlockIt extends the CHtmlBlock class. I don't see the code for that one. Presumably the parse method is in there somewhere.
Sorry to know where to find the class the code for the function.php file is:
Link to comment
Share on other sites

I'm not seeing the class in there, did you see it?
No, I'm not too sure where to find the class - I didsearch for it, but that said there was over 300 pages containing CHtmlBlock, nothing came up at all if I searched for CHtmlBlock class or function CHtmlBlock. Should I be searching for something else?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...