• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: SQL query to show results on the same page

SQL query to show results on the same page 17 years 7 months ago #1207

Hallo,

Great components, bought rsForm & rsFiles.

Is it possible to make a sql query with a form to search data and show the result on the same page?

Greetz.

Reddelberg.
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 7 months ago #1210

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
Hello Reddelberg,

sure you can. When you edit your form, go to the scripts tab. You will see there Scripts called on form display: and Scripts called on form process. What you need i think it has to be on the form display. But i'll need more info on what exactly you need to search, and how you want to display it, and i'll help you create the script you need.
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 7 months ago #1222

Hi,

I haven a form to add data called \"Overname plaatsen\". http://www.creabella.be/livedemo/index.php?option=com_forme&fid=1
I have a second form to search data called \"Overname zoeken\". http://www.creabella.be/livedemo/index.php?option=com_forme&fid=4

Is it possible to enter some fields (text, select) in the second form, to search the data and show it on the same page? Like only those records with zipcode 3800 ... or region Limburg ...

Thanks

Reddelberg
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 7 months ago #1225

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
Hi Reddelberg,

I would suggest you to use the mod_forme_list module that you can download by clicking on Support > Files. After you install it, it will show you all the data.

Then, you will have to customize it, in order to make it fit your needs. Edit the file and replace this code:
if($check){
	require_once($elpath.'/languages/'.$check.'.php');
}else{
	require_once($elpath.'/languages/en.php');
}
 
$database->SetQuery( \"SELECT count(*)\"
					. \"\nFROM #__forme_data AS a\"
					. \"\nWHERE a.form_id = '$fid'\"
					);
$total = $database->loadResult();
$pageNav = new mosPageNav( $total, $limitstart, $limit );
 
$database->setQuery(\"SELECT * FROM #__forme_data WHERE form_id = '$fid' ORDER BY date_added DESC\", $pageNav->limitstart, $pageNav->limit );
$data = $database->loadObjectList();

With this code:
if($check){ require_once($elpath.'/languages/'.$check.'.php'); }else{ require_once($elpath.'/languages/en.php'); } ?> <form name=\"Overnamezoeken\" id=\"Overnamezoeken\" method=\"post\" action=\"\" > <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"forme\"> <tr> <td align=\"right\" valign=\"top\">Regio</td> <td valign=\"top\"><select name=\"form[Regio][]\" id=\"Regio\" ><option value=\"W-Vlaanderen\">W-Vlaanderen </option><option value=\"O-Vlaanderen\">O-Vlaanderen </option><option value=\"Limburg\">Limburg </option><option value=\"Antwerpen\">Antwerpen </option><option value=\"Vlaams-Brabant\">Vlaams-Brabant </option><option value=\"Waals-Brabant\">Waals-Brabant </option><option value=\" Henegouwen\">Henegouwen </option><option value=\"Luik\">Luik </option><option value=\"Luxemburg\">Luxemburg </option><option value=\"Namen\">Namen</option></select></td> <td valign=\"top\"></td> </tr> <tr> <td align=\"right\" valign=\"top\">Postcode *</td> <td valign=\"top\"><input type=\"text\" name=\"form[Postcode]\" value=\"\" id=\"Postcode\" /></td> <td valign=\"top\"></td> </tr> <tr> <td align=\"right\" valign=\"top\">Prijs</td> <td valign=\"top\"><select name=\"form[Prijs][]\" id=\"Prijs\" ><option value=\"Minder dan [code]
if($check){
require_once($elpath.'/languages/'.$check.'.php');
}else{
require_once($elpath.'/languages/en.php');
}

?>
<form name=\"Overnamezoeken\" id=\"Overnamezoeken\" method=\"post\" action=\"\" >
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"forme\">
<tr>
<td align=\"right\" valign=\"top\">Regio</td>

<td valign=\"top\"><select name=\"form[Regio][]\" id=\"Regio\" ><option value=\"W-Vlaanderen\">W-Vlaanderen </option><option value=\"O-Vlaanderen\">O-Vlaanderen </option><option value=\"Limburg\">Limburg </option><option value=\"Antwerpen\">Antwerpen </option><option value=\"Vlaams-Brabant\">Vlaams-Brabant </option><option value=\"Waals-Brabant\">Waals-Brabant </option><option value=\" Henegouwen\">Henegouwen </option><option value=\"Luik\">Luik </option><option value=\"Luxemburg\">Luxemburg </option><option value=\"Namen\">Namen</option></select></td>
<td valign=\"top\"></td>
</tr>
<tr>
<td align=\"right\" valign=\"top\">Postcode *</td>

<td valign=\"top\"><input type=\"text\" name=\"form[Postcode]\" value=\"\" id=\"Postcode\" /></td>
<td valign=\"top\"></td>
</tr>
<tr>
<td align=\"right\" valign=\"top\">Prijs</td>
<td valign=\"top\"><select name=\"form[Prijs][]\" id=\"Prijs\" ><option value=\"Minder dan
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 7 months ago #1229

Hallo,

I have installed the mod_forme_list module without editing it. The results will not show up on the page. iIhave 2 records to show. The only thing that appear is {fullname} and {email}

Thanks

Reddelberg
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 7 months ago #1231

  • alex
  • alex's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 443
  • Thank you received: 3
Hi Reddelberg,

as a first step, go to your back-end, in the Modules, edit the mod_forme_list module, and in the Row Layout change the default code to something like this:
&lt;tr&gt;&lt;td&gt;{Postcode}&lt;/td&gt;&lt;td&gt;{Prijs}&lt;/td&gt;&lt;td&gt;{Sector}&lt;/td&gt;&lt;td&gt;{Zoekterm}&lt;/td&gt;&lt;/tr&gt;
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 3 months ago #2078

  • tsanne
  • tsanne's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi - I'm trying to do something very similar to this. I've modified the code in mod_forme_list.php as suggested, but when the form is displayed and the search is submitted, I get an error on the following code:

foreach($data as $i=>$data_row)

Here's the error:

Warning: Invalid argument supplied for foreach() in /usr/home/tsanne/public_html/joomla/modules/mod_forme_list/mod_forme_list.php on line 102

I'm attaching the modified file.
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 3 months ago #2079

  • tsanne
  • tsanne's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Alright, can't upload the file. So, here's the contents of mod_forme_list.php:

<?php
/**
* @version 1.0.4
* @package Mod Forme List 1.0.4
* @copyright (C) 2007 www.rsjoomla.com
* @license Commercial License, www.pimpmyjoomla.com/license/forme.html
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

$fid = intval( $params->def( 'form_id', 0 ) );
$template_module = $params->def( 'template_module', '' );
$template_formdatarow = $params->def( 'template_formdatarow', '' );
$limit = intval( $params->def( 'limit', 15 ) );
$limitstart = intval( JRequest::getVar('limitstart', 0 ) );

global $database,$limitstart;
require_once(JPATH_SITE.'/includes/pageNavigation.php');

$CONFIG = new JConfig();
$my = & JFactory::getUser();
$database =& JFactory::getDBO();


$elpath = JPATH_SITE.'/components/com_forme';

//check language
//first check global joomfish
$check = false;
if(isset($_COOKIE)) $check = $_COOKIE;
if(isset($_REQUEST)) $check = JRequest::getVar('lang',false);

//removed code suggested in post 1225

if($check){
require_once($elpath.'/languages/'.$check.'.php');
}else{
require_once($elpath.'/languages/en.php');
}

?>
<form name=\"smallGroupEntryForm\" id=\"2\" method=\"post\" action=\"\" >
<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"forme\">
<tr>
<td align=\"right\" valign=\"top\">Small Group Type</td>

<td valign=\"top\"><select name=\"form[sgtype][]\" id=\"sgtype\" ><option value=\"%\">All Types </option><option value=\"Mixed\">Mixed </option>
<option value=\"Singles (19-29)\">Singles (19-29) </option><option value=\"Women\">
Women </option><option value=\"Men\">Men </option><option value=\"Young Married\">Young Married </option>
<option value=\"Plus 55\">Plus 55 </option></select></td>
<td valign=\"top\"></td>

<td align=\"right\" valign=\"top\">Day of Week</td>
<td valign=\"top\"><select name=\"form[sgmtgdayofweek][]\" id=\"sgmtgdayofweek\" ><option value=\"Sunday\">
Sunday </option><option value=\"Monday\">Monday </option>
<option value=\"Tuesday\">Tuesday </option><option value=\"Wednesday\">Wednesday </option>
<option value=\"Thursday\">Thursday </option>
<option value=\"Friday\">Friday </option><option value=\"Saturday\">Saturday </option>
</select></td>
<td valign=\"top\"></td>

</tr>
<tr>
<td align=\"right\" valign=\"top\">Search</td>
<td valign=\"top\"><input type=\"submit\" name=\"form[Search]\" value=\"Search\" id=\"Search\" /></td>
<td valign=\"top\"></td>

</tr>

</table>
</form>
<?php

$wheres = array();
$form = mosGetParam($_POST,'form',array());

if($form!='') $wheres[] = \"params LIKE '%\".$form.\"%'\";
if($form!='') $wheres[] = \"params LIKE '%\".$form.\"%'\";


$query = \"SELECT count(*) FROM #__forme_data AS a WHERE a.form_id = '$fid'\".implode( ' AND ',
$wheres );
$database->SetQuery( $query);
$total = $database->loadResult();
$pageNav = new mosPageNav( $total, $limitstart, $limit );

$query = \"SELECT * FROM #__forme_data AS a WHERE a.form_id = '$fid'\".implode( ' AND ', $wheres );
$database->setQuery($query, $pageNav->limitstart, $pageNav->limit );
$data = $database->loadObjectList();


//load fields
$database->setQuery(\"SELECT * FROM #__forme_fields WHERE form_id = '$fid' AND published=1\");
$fields = $database->loadObjectList();

$html = '';


foreach($data as $i=>$data_row){
//parse parameters
$database->setQuery(\"SELECT * FROM #__users WHERE id = '$data_row->uid'\");
$user = $database->loadObject();

$prm = array();
$prm = $CONFIG->sitename;
$prm = JURI::base();
$prm = $data_row->uip;
$prm = $data_row->uid;
$prm = date(_FORME_DATETIME,strtotime($data_row->date_added));
$prm = (isset($user->username)) ? $user->username : 0;
$prm = (isset($user->email)) ? $user->email : 0;
$prm = $i+$pageNav->limitstart+1;

$prm_explode = explode(\"||\n\",$data_row->params);
foreach($prm_explode as $param_row){
$param_row = explode('=',$param_row,2);
if(isset($param_row[1])){
$prm[$param_row[0]] = $param_row[1];
}else{
$prm[$param_row[0]] = '';
}
}
$temp_html = $template_formdatarow;
foreach($fields as $field){
if(!isset($prm[$field->name])) $prm[$field->name] = '';
$temp_html = str_replace('{'.$field->name.'}',$prm[$field->name],$temp_html);
}

$html .= $temp_html;
}


//load fields
$database->setQuery(\"SELECT * FROM #__forme_fields WHERE published = 1 AND form_id = '$fid'\");
$fields = $database->loadObjectList();
foreach($fields as $field){
$template_module = str_replace('{'.$field->name.'}',$field->title,$template_module);
}
$template_module = str_replace('{formdata}',$html,$template_module);

echo $template_module;
if($total>$limit) echo '<div class=\"pageNav\">'.$pageNav->writePagesLinks($_SERVER.'?'.$_SERVER).'</div>';
echo '<div class=\"pageNav\">'.$pageNav->writePagesCounter().'</div>';

?><br><br>Post edited by: tsanne, at: 2008/02/22 05:28
The administrator has disabled public write access.

Re:SQL query to show results on the same page 17 years 3 months ago #2106

  • tsanne
  • tsanne's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Okay, I made this work. Figured I'd post what I did in case somebody else needs to do something similar. Here's the code I ended with:

Something to bear in mind is that if you update the database directly, you will have problems with getting the explode function to work properly because the code below explodes on \"\n\" which goes away if you update the database directly.

<?php
/**
* @version 1.0.4
* @package Mod Forme List 1.0.4
* @copyright (C) 2007 www.rsjoomla.com
* @license Commercial License, www.pimpmyjoomla.com/license/forme.html
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

$fid = intval( $params->def( 'form_id', 0 ) );

$template_module = $params->def( 'template_module', '' );
$template_formdatarow = $params->def( 'template_formdatarow', '' );
$limit = intval( $params->def( 'limit', 15 ) );
$limitstart = intval( JRequest::getVar('limitstart', 0 ) );

global $database,$limitstart;
require_once(JPATH_SITE.'/includes/pageNavigation.php');

$CONFIG = new JConfig();
$my = & JFactory::getUser();
$database =& JFactory::getDBO();


$elpath = JPATH_SITE.'/components/com_forme';

//check language
//first check global joomfish
$check = false;
if(isset($_COOKIE)) $check = $_COOKIE;
if(isset($_REQUEST)) $check = JRequest::getVar('lang',false);

//removed code suggested in post 1225

if($check){
require_once($elpath.'/languages/'.$check.'.php');
}else{
require_once($elpath.'/languages/en.php');
}

?>
<form name=\"smallGroupEntryForm\" id=\"smallGroupEntryForm\" method=\"post\" action=\"\" >
<table width=\"80%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" class=\"forme\">
<tr>
<td valign=\"top\">Small Group Type</td><td>Day of Week</td></tr><tr>

<td valign=\"top\"><select name=\"smallGroupEntryForm[sgtype][]\" id=\"sgtype\" ><option value=\"%\">All Types </option><option value=\"Mixed\">Mixed </option>
<option value=\"Singles (19-29)\">Singles (19-29) </option><option value=\"Women\">
Women </option><option value=\"Men\">Men </option><option value=\"Young Married\">Young Married </option>
<option value=\"Plus 55\">Plus 55 </option></select></td>

<td valign=\"top\"><select name=\"smallGroupEntryForm[sgmtgdayofweek][]\" id=\"sgmtgdayofweek\" ><option value=\"Any\">Any</option><option value=\"Sunday\">
Sunday </option><option value=\"Monday\">Monday </option>
<option value=\"Tuesday\">Tuesday </option><option value=\"Wednesday\">Wednesday </option>
<option value=\"Thursday\">Thursday </option>
<option value=\"Friday\">Friday </option><option value=\"Saturday\">Saturday </option>
</select></td>
<td valign=\"top\"><input type=\"submit\" name=\"form[Search]\" value=\"Search\" id=\"Search\" /></td>
</tr>
<tr><td colspan=\"3\"> </td></tr>
</table>
</form>
<?php

$wheres = array();
$form = mosGetParam($_POST,'smallGroupEntryForm',array());

$sgtypechoice = $form[0];
$sgmtgdayofweekchoice = $form[0];

if($sgtypechoice == 'All Types') $sgtypechoice='%';
if($sgmtgdayofweekchoice == 'Any') $sgmtgdayofweekchoice='%';

if($form!='') $wheres[] = \"params LIKE '%sgtype=\".$sgtypechoice.\"%'\";
if($form!='') $wheres[] = \"params LIKE '%sgmtgdayofweek=\".$sgmtgdayofweekchoice.\"%'\";

$query = \"SELECT count(*) FROM jos_forme_data AS a WHERE a.form_id = '$fid' and \".implode( ' AND ',
$wheres );
$database->setQuery($query);
$total = $database->loadResult();

$pageNav = new mosPageNav( $total, $limitstart, $limit );

$query = \"SELECT * FROM jos_forme_data AS a WHERE a.form_id = '$fid' and \".implode( ' AND ', $wheres );

$database->setQuery($query, $pageNav->limitstart, $pageNav->limit );
$data = $database->loadObjectList();


//load fields
$database->setQuery(\"SELECT * FROM jos_forme_fields WHERE form_id = '$fid' AND published=1\");
$fields = $database->loadObjectList();

$html = '';

if($data!='') {
foreach($data as $i=>$data_row){
//parse parameters
$database->setQuery(\"SELECT * FROM jos_users WHERE id = '$data_row->uid'\");
$user = $database->loadObject();

$prm = array();
$prm = $CONFIG->sitename;
$prm = JURI::base();
$prm = $data_row->uip;
$prm = $data_row->uid;
$prm = date(_FORME_DATETIME,strtotime($data_row->date_added));
$prm = (isset($user->username)) ? $user->username : 0;
$prm = (isset($user->email)) ? $user->email : 0;
$prm = $i+$pageNav->limitstart+1;

$prm_explode = explode(\"||\n\",$data_row->params);
foreach($prm_explode as $param_row){
$param_row = explode('=',$param_row,9);

if(isset($param_row[1])){
$prm[$param_row[0]] = $param_row[1];
}else{
$prm[$param_row[0]] = '';
}
}
$temp_html = $template_formdatarow;

foreach($fields as $field){
if(!isset($prm[$field->name])) $prm[$field->name] = '';
$temp_html = str_replace('{'.$field->name.'}',$prm[$field->name],$temp_html);
}

$html .= $temp_html;
}
}

//load fields
$database->setQuery(\"SELECT * FROM jos_forme_fields WHERE published = 1 AND form_id = '$fid'\");
$fields = $database->loadObjectList();

foreach($fields as $field){
$template_module = str_replace('{'.$field->name.'}',$field->title,$template_module);
}
$template_module = str_replace('{formdata}',$html,$template_module);

echo $template_module;
if($total>$limit) echo '<div class=\"pageNav\">'.$pageNav->writePagesLinks($_SERVER.'?'.$_SERVER).'</div>';
echo '<div class=\"pageNav\">'.$pageNav->writePagesCounter().'</div>';

?>
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!