How to create a search button on a form

dianaj59 20 Apr, 2009
I am using Joomla 1.5
I want to create a search button on my form.
I want to use a drop down box that reflects one field from the database (lastname).
The table name is jos_Teacher_Registration.
When a name is chosen I want all the fields on the form to appear.

I only have the very basic html to put in the form code.
Can anyone help me with what is needed?
This is all I have so far. Just the shell really.
<method="get" action="jos_Teacher_Registration">
<div style="border:1px solid black;padding:4px;width:20em;">
<table border="0" cellpadding="0">
<tr><td>
<input type="text"   name="lastname" size="25" maxlength="255" value="" />
<input type="submit" value="Teacher LookUp" /></td></tr>
<tr><td align="center" style="font-size:75%">
</td></tr></table>
</div>
dianaj59 20 Apr, 2009
I found some php code that I think will work.
It connects to the database, but there is a syntax error that I can not find.
Any ideas?
(I took out my dbname, username and password to post it here).

<head><title>Teacher LookUp Page</head>
<?php
$database="dbname";
mysql_connect ("localhost", "username", "password");
@mysql_select_db($database) or die("Unable to select database");

<select size="1" name="select">
<?
$result=mysql_query("select * from `jos_chronoforms_teacher_registration` ORDER BY `id` DESC");
while ($row=mysql_fetch_array($result)){
$id=$row['id'];
$lastname=$row['lastname'];?>
<option value="<? echo $id; ?>"><? echo $lastname; ?></option><?}?>
</select>

dianaj59 20 Apr, 2009
THIS CODE WORKS:
<head><title>Teacher LookUp Page</head>
<?php
$database="dbname";
mysql_connect ("localhost", "username", "passwprd");
@mysql_select_db($database) or die("Unable to select database");
?>
<select size="1" name="select">
<?
$result=mysql_query("select * from `jos_chronoforms_teacher_registration` ORDER BY `id` DESC");
while ($row=mysql_fetch_array($result)){
$id=$row['id'];
$lastname=$row['lastname'];?>
<option value="<? echo $id; ?>"><? echo $lastname; ?></option><?}?>
</select>

EXCEPT NOW....
I get the following error across the top of my page:
Error loading Modules:
Error loading Modules:
Error loading Modules:
Error loading Modules:
Error loading Modules:
Error loading Modules:
SIX times for the number I want in my drop down list. The drop down appears on the page, but is empty.
Thanks for any help on this.

Also the SEARCH PART of the Code has not been figured out....thx.
dianaj59 20 Apr, 2009
Okay. I'm forgetting about the drop down.
Let's try just a plain search button. With the following code I get the search box, but when I enter into it, I get the message:
You are not allowed to access this URL
Does anyone know what causes this probelm?
Where can I change things to make this work properly?
Thanks.

Feels like I'm talking to myself, but I figured others can use this information too.

The code for the search box on a web page is:
<head><title>Teacher LookUp Page</head> 

<?

if (isset($_POST['search'])){
$keyword=$_POST['keyword'];
$sql="SELECT * FROM jos_chronoforms_teacher_registration WHERE `lastname` LIKE '%$keyword%' ORDER BY id DESC";
$result = mysql_query($sql);

$query = mysql_fetch_array($result);

echo $query['id'].' ';

echo $query['lastname'];

}

?>

<form method="POST" action="<? echo PHP_SELF; ?>">
<p> </p>
<table border="0" width="100%" id="table1">
<tr>
<td align="center"> </td>
<td width="119" align="center">
<address align="right">
<span style="font-style: normal">
<input type="text" name="keyword" size="33" class="text"></span></address>
<address align="right">
<span style="font-style: normal">
<font face="Verdana" size="2" color="#FFFFFF">
<input type=submit value="Search" style="color: #6A0204; font-family: verdana; font-weight: normal; font-size:10px; background-color: #FFFFFF; float:center" name="search"></font></span></address>
</td>
<td width="30"> </td>
</tr>
</table>
</form></select>
Max_admin 21 Apr, 2009
Hi Diana,

in the form HTML box, add the input box HTML code, in the form onSubmit box, add this


global $mainframe;
$database =& JFactory::getDBO();
$sql="SELECT * FROM jos_chronoforms_teacher_registration WHERE `lastname` LIKE '%$keyword%' ORDER BY id DESC";
$database->setQuery( $query );
$results = $database->loadObjectList();


now you can loop through results with foreach like:

foreach($results as $result){
echo $result->something;
}


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dianaj59 21 Apr, 2009
After I enter a search keyword, I still get the message:
You are not allowed to access this URL

I'm also not sure I understand what you told me to do.
Here is the code I'm using:
In FormHTML
<head><title>Teacher LookUp Page</head> 
<?

if (isset($_POST['search'])){
$keyword=$_POST['keyword'];
$sql="SELECT * FROM jos_chronoforms_teacher_registration WHERE `lastname` LIKE '%$keyword%' ORDER BY id DESC";
$result = mysql_query($sql);

$query = mysql_fetch_array($result);

echo $query['id'].' ';

echo $query['lastname'];

}

?>
<form method="POST" action="<? echo PHP_SELF; ?>">
<p> </p>
<table border="0" width="100%" id="table1">
<tr>
<td align="center"> </td>
<td width="119" align="center">
<address align="right">
<span style="font-style: normal">
<input type="text" name="keyword" size="33" class="text"></span></address>
<address align="right">
<span style="font-style: normal">
<font face="Verdana" size="2" color="#FFFFFF">
<input type=submit value="Search By Last Name" style="color: #6A0204; font-family: verdana; font-weight: normal; font-size:10px; background-color: #FFFFFF; float:center" name="search"></font></span></address>
</td>
<td width="30"> </td>
</tr>
</table>
</form></select>

<?


In Form OnSubmit:
global $mainframe;
$database =& JFactory::getDBO();
$sql="SELECT * FROM jos_chronoforms_teacher_registration WHERE `lastname` LIKE '%$keyword%' ORDER BY id DESC";
$database->setQuery( $query );
$results = $database->loadObjectList();


If I need to change something please let me know.
Thanks.
dianaj59 23 Apr, 2009
I found that my mistake was having the <form> tag in my html code.
When I took that out I no longer got the error "You are not allowed to access this URL"

Because I am not too experienced with php code. I am having a hard time getting the fields found in the database to display on my form. I can enter into the search box and it returns my page, but he page is blank. Can you tell me how to write the code to display what the search criteria finds. I suppose I'll need a message that lets them know if it doesn't find anything also.

Here is what I have right now:
HTML FORM:
<head><title>Teacher LookUp Page</head> 

<method="POST" action="<? echo PHP_SELF; ?>">
<p> </p>
<table border="0" width="100%" id="table1">
<tr>
<td align="center"> </td>
<td width="119" align="center">
<address align="right">
<span style="font-style: normal">
<input type="text" name="keyword" size="33" class="text"></span></address>
<address align="right">
<span style="font-style: normal">
<font face="Verdana" size="2" color="#FFFFFF">
<input type=submit value="Search By Last Name" style="color: #6A0204; font-family: verdana; font-weight: normal; font-size:10px; background-color: #FFFFFF; float:center" name="search"></font></span></address>
</td>
<td width="30"> </td>
</tr>
</table>



ONSUBMIT CODE
<?

if (isset($_POST['search'])){
$keyword=$_POST['keyword'];
$sql="SELECT * FROM jos_chronoforms_teacher_registration WHERE `lastname` LIKE '%$keyword%' ORDER BY id DESC";
$result = mysql_query($sql);

$query = mysql_fetch_array($result);

while ($row=mysql_fetch_array($result)){

$lastname=$row['lastname'];
}
echo $lastname."<br>";

echo $query['id'].' ';
 
echo $query['lastname'];

?>



Thanks for any help!
GreyHead 24 Apr, 2009
Hi dianaj59,

Just to be clear - you are asking about ChronoForms? (this is the ChronoComments forum).

You also have some odd things in your code. The <method> tag doesn't exist in HTM as far as I know, and the <address> has only a specialised used - I think you mean <label> here. The <head> tag is good but should never appear in the form html.
<table border="0" width="100%" id="table1">
  <tr>
    <td align="center"> </td>
    <td width="119" align="center">
      <label align="right">
        <input type="text" name="keyword" size="33" class="text">
      </label>
      <input type=submit value="Search By Last Name" style="color: #6A0204; font-family: verdana; font-weight: normal; font-size:10px; background-color: #FFFFFF; float:center;" name="search">
    </td>
    <td width="30"> </td>
  </tr>
</table>

The OnSubmit code woudl be better written using Joomla code
<?php
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword, '', 'post');
if ( $keyword ) {
  $sql="
    SELECT * 
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%' 
      ORDER BY `id` DESC";
$db->setQuery($sql);
$results = $db->loadResultArray();
foreach ($results as $result ) {
  echo $result['lastname']."<br />".$result['id']." ".result['lastname'];
}
?>
Not tested and will need debugging.

Bob
dianaj59 24 Apr, 2009
Sorry, yes, this should be under ChronoForms.

Two more questions.
1. On Submit, I want the page to reload displaying the end result of lastname. This is not happening. Do I need something more in the html code to display what the Joomla code has queried and found?

2. Can you guide me to a tutorial to learn "joomla code"?

Thanks for your help on this.
dianaj59 24 Apr, 2009
Do I need ChronoConnectivity to accomplish this?
Is that the only way?
Max_admin 24 Apr, 2009
Hi Diana,

I think that I answered a post yesterday for you with some code, I asked you to remove 2 or 3 lines!!! we need to work in one topic only please!

Whats the problem with Bob's code above ? I see it should work fine!

you don't need Connectivity to accomplish this! Chronoforms is fine!

I suggest you get a book about J1.5 code development first!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dianaj59 24 Apr, 2009
You did give me code yesterday.
I had code that I showed.
I am now using the code given here.
I've closed the other threads, i think.

I think I must not be communicating well enough, but I'll try again.

I have a form that has a search input box on it.
The user is to enter a last name into the search input box.

Here is the code for the search box entered into the HTML FORM:
    <table border="0" width="100%" id="table1">
      <tr>
        <td align="center"> </td>
        <td width="119" align="center">
          <label align="right">
            <input type="text" name="keyword" size="33" class="text">
          </label>
          <input type=submit value="Search By Last Name" style="color: #6A0204; font-family: verdana; font-weight: normal; font-size:10px; background-color: #FFFFFF; float:center;" name="search">
        </td>
        <td width="30"> </td>
      </tr>
    </table>


Here is the php code to query the database and compare the keyword with the search box word.
This is entered in the ONSUBMIT:
<?php
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword, '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `id` DESC";
$db->setQuery($sql);
$results = $db->loadRowList();
foreach ($results as $result ) {
  echo $result['lastname']."<br />".$result['id']." ".$result['lastname'];
}
?>


My Problem is that after the last name is entered into the search input box, I want the information found in the database to be displayed on the page. What happens now is that the page reloads (redirect url default) as a blank page.
I don't know how to make this work.
Thanks.
Max_admin 24 Apr, 2009
Hi Diana,

If you don't have a redirect URL then the results should be shown fine!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 24 Apr, 2009
Hi dianaj59,

First off - please only post your questions once, it;s very confusing to find three threads in different forums with the same question. And its a waste of your time and ours when you get several answers in different places.

I'm not sure what you mean by (redirect url default)? If you have anything in the ReDirect URL please remove it. The code I posted *should* show you the results after the form is submitted.

If you want to show the results and re-show the form that can be done but let's get some results showing first.

Bob
dianaj59 25 Apr, 2009
I am sorry about posting my question with multiple threads. It won't happen again.

What I mean by "default redirect url" is in the Form URLs tab, there are two options; "Redirect URL" and "Submit URL". I have absolutely nothing in either one. Once a search criteria was entered into the search box and enter is hit, I wanted it to reload the page WITH the lastname field from the database appearing. As it is right now using your code, (I copied and pasted it), I get a blank page.

I will appreciate any help.
If it works for you, then I must have something wrong somewhere, but I can not see it.
GreyHead 25 Apr, 2009
Hi dianaj59,

OK that's fine.

Zeroth check: if you are using the OnSubmit Before box make sure that Emails are enabled in the General tab or the code will not run.

There's probably a typo in my code somewhere, or the database query isn't returning any results.

First test: add an output line near the beginning:
<?php
echo '<div>XXX</div>';
$db =& JFactory::getDBO();
. . .
This should output XXX on your blank page. If it doesn't then there is a bigger problem somewhere.

Second test: turn on Debug in your site Global Configuration (NB Do not do this on live sites at busy times), then submit the form. Look through the Debug output at the foot of the page for the $sql query; copy and paste the query and any related error messages into notepad or some other editor. Turn Site Debug off again.

Check the error messages and sql. I usually paste the sql into PHPMyAdmin or EasySQL and tweak it to remove any errors and get the result I want - then transpose the fixes back into the OnSubmit code.

Bob

PS The best source for Joomla Code is the Joomla dev wiki you can access through joomla.org. Not perfect or complete but increasingly full of useful stuff.
dianaj59 25 Apr, 2009
I am using the OnSubmit Before box.
My email was NOT enabled.
I enabled this and after I enter my search box criteria I got an error message:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/global22/public_html/components/com_chronocontact/chronocontact.php(371) : eval()'d code on line 3

I added the line of code as you suggested...
echo '<div>XXX</div>';
(I put this just after <?php)
I got the above error again only referencing line 4 instead of 3. Makes sense since I added that line.

I turned the debugger on.
I'll paste in here the first four items it brings back.

setRefTables debug:
tempsql = select distinct reference_table from jos_jf_content
sql_exNos = select distinct reference_table from jos_jf_content

setRefTables debug:
tempsql = select distinct reference_table from jos_jf_content
sql_exNos = select distinct reference_table from jos_jf_content

setRefTables debug:
tempsql = SELECT m.*, c.`option` as component FROM jos_menu AS m LEFT JOIN jos_components AS c ON m.componentid = c.id WHERE m.published = 1 ORDER BY m.sublevel, m.parent, m.ordering
sql_exNos = SELECT m.*, c.`option` as component FROM jos_menu AS m LEFT JOIN jos_components AS c ON m.componentid = c.id WHERE m.published = ORDER BY m.sublevel, m.parent, m.ordering

setRefTables debug:
tempsql = SELECT template FROM jos_templates_menu WHERE client_id = 0 AND (menuid = 0 OR menuid = 0) ORDER BY menuid DESC LIMIT 0, 1
sql_exNos = SELECT template FROM jos_templates_menu WHERE client_id = AND (menuid = OR menuid = ) ORDER BY menuid DESC LIMIT ,



The Complete name of my table is jos_chronoforms_teacher_registration
I changed that small part of your SELECT statement, but it made NO difference.

I'm not sure what else to try, but I'll keep looking at it.
Thanks Again.
dianaj59 25 Apr, 2009
UPDATE:
Found the error on line 3. There was not a single end quote after keyword:
Code Changed as follows:
<?php
echo '<div>XXX</div>';
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword', '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `id` DESC";
$db->setQuery($sql);
$results = $db->loadResultArray();
foreach ($results as $result ) {
  echo $result['lastname']."<br />".$result['id']." ".result['lastname'];
}
?>


Now Error on line 14:
  echo $result['lastname']."<br />".$result['id']." ".result['lastname'];


I'll keep looking.
dianaj59 25 Apr, 2009
There seems to be a problem I can not find in this line of code:
  echo $result['lastname']."<br />".$result['id']." ".result['lastname'];

The error is:
[quote]Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/global22/public_html/components/com_chronocontact/chronocontact.php(371) : eval()'d code on line 14[/quote]

I've tried it with a $ in front of the last "result" too:
  echo $result['lastname']."<br />".$result['id']." ".$result['lastname'];

but still no luck. The error is:

Parse error: syntax error, unexpected $end in /home/global22/public_html/components/com_chronocontact/chronocontact.php(371) : eval()'d code on line 16



Thanks
GreyHead 26 Apr, 2009
Hi dianaj59,

There's certainly a missing $ - apologies for that.

Also change the $results line to
$results = $db->loadRowList();


Otherwise it looks OK - but will not output anything much if $result is empty.

Bob

PS Joomla will replace #__ with jos_ if that's the correct prefix for your site.
dianaj59 26 Apr, 2009
I made the changes you suggested.
I looked in the table to verify there is a last name to match the criteria I am entering into the search box.
Something still seems to be troubling to the system at the end of this code.
The error message is:

Parse error: syntax error, unexpected $end in /home/global22/public_html/components/com_chronocontact/chronocontact.php(371) : eval()'d code on line 16



line 16 is the very last line of code
?>


Looking to the future.
If or when we get this problem figured out, I'm going to need to add in a IF statement that gives a message to the user if the keyword is not found in the table; likewise if there are more than one match it will need to give the user the option to choose which one. BUT, that is getting ahead of myself. The issue at hand must be resolved first.
GreyHead 26 Apr, 2009
Hi dianaj59,

That sounds like a missing ; from the end of a line. Please will you cut and paste all 16 lines that you have now so I can take a look.

Bob
dianaj59 26 Apr, 2009
Here is the code as I have it now:
<?php
echo '<div>XXX</div>';
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword', '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `id` DESC";
$db->setQuery($sql);
$results = $db->loadRowList();
foreach ($results as $result ) {
  echo $result ['lastname']."<br />".$result ['id']." ".$result ['lastname'];

}
?>


I found another strange occurrence. Each time I enter a name and search for it a blank record is entered into the database. This is not good.

Here is some of what I have set in the general tab:
Email Results - yes
Form tag attachments - enctype='multipart/form-data' (not sure where this came from)
Form method - post
Mysql statment - Engine
dianaj59 26 Apr, 2009
UPDATE:
Under the tab DB Connection.
I set Enable Data storage: to NO.

That appears to have resolved the blank records issue.
GreyHead 26 Apr, 2009
Hi dianaj59,

The code needs one more }
<?php
echo '<div>XXX</div>';
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword', '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `id` DESC";
  $db->setQuery($sql);
  $results = $db->loadRowList();
  foreach ($results as $result ) {
    echo $result ['lastname']."<br />".$result ['id']." ".$result ['lastname'];
  }
}
?>

Bob
dianaj59 26 Apr, 2009
GREAT!
This code works now.
However, it does not bring back the information from the database.
the sql statement says "SELECT * FROM...."
I want to see this information on the page.
I think we need to add a line of code to see it.
I've tried:
foreach ($results as $result ); {
  echo $result ['lastname']."<br />".$result ['id']." ".$result ['lastname'];
}
print "The last name is $results <P>";
}

But that is not right. That brings back a result of:
The last name is Array
How should this be done?
Thanks.
GreyHead 26 Apr, 2009
Hi dianaj59,

That's what this line does:
echo $result ['lastname']."<br />".$result ['id']." ".$result ['lastname'];
echo is much the same as print. The question is why no reults are showing up. Check the Global Debug results again and see if there are any results being fround from the query.

Bob
dianaj59 26 Apr, 2009
I went back to look at the table and yes, the actual field name for the unique identifier is uid, not id.
I changed the code as follows:
<?php
echo '<div>XXX</div>';
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword', '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `uid` DESC";
$db->setQuery($sql);
$results = $db->loadRowList();
foreach ($results as $result ); {
  echo $result ['lastname']."<br />".$result ['uid']." ".$result ['lastname'];
}
}
?>


I still did not get the desired printout.
I am seeing the XXX, though, so I turned on the debugger.
The following is what I see, beginning with the XXX.

XXX

setRefTables debug:
tempsql = SELECT * FROM `jos_chronoforms_teacher_registration` WHERE `lastname` LIKE '%Walters%' ORDER BY `uid` DESC
sql_exNos = SELECT * FROM `jos_chronoforms_teacher_registration` WHERE `lastname` LIKE '%Walters%' ORDER BY `uid` DESC

setRefTables debug:
tempsql = SELECT * FROM jos_chrono_contact_plugins WHERE form_id='3' AND event='ONSUBMIT' AND name=''
sql_exNos = SELECT * FROM jos_chrono_contact_plugins WHERE form_id='' AND event='ONSUBMIT' AND name=''



Does this help you understand what might be wrong, because I'm having a hard time seeing what the problem is. My form id is 3, so that looks right. There is a record with the lastname of "Walters", so that should work.
GreyHead 26 Apr, 2009
Hi dianaj59,

It's going to be something silly in the end.

Two things to try, one is to paste the SQL into PHPMyAdmin (or the EasySQL extension) and see what results show up
SELECT * FROM `jos_chronoforms_teacher_registration` WHERE `lastname` LIKE '%Walters%' ORDER BY `uid` DESC


Second, add a debug line or two into the code
. . .
$db->setQuery($sql);
echo '<div>$sql: '.print_r($sql, true).'</div>';
$results = $db->loadRowList();
echo '<div>$results: '.print_r($results, true).'</div>';
foreach . . .

Bob
dianaj59 26 Apr, 2009
I did the sql query in phpMyAdmin. I got the desired result.
I added your two lines of debug code and got this:

$sql: SELECT * FROM `#__chronoforms_teacher_registration` WHERE `lastname` LIKE '%Walters%' ORDER BY `cf_id` DESC
$results: Array ( [0] => Array ( [0] => 30 [1] => INGVkZGE0NjFhNzQ4 [2] => 2009-03-31 - 15:34:11 [3] => 204.169.30.3 [4] => 0 [5] => Terry [6] => [7] => Walters [8] => September 6, 1050 [9] => 3600 44th Ave S [10] => Minneapolis [11] => MN [12] => 55406 [13] => 612-724-0365 [14] => [15] => [email]twalters3600@yahoo.com[/email] [16] => US [17] => teacher [18] => [19] => terry walters [20] => [21] => [22] => [23] => [24] => [25] => [26] => [27] => [28] => [29] => [30] => [31] => [32] => [33] => [34] => f [35] => y [36] => [37] => ) )



Looks to me like we need to refer to an array number like [7] instead of [lastname], so I tried this change in the code:
foreach ($results as $result ); {
  echo "Last Name is: " .$result [7]."<br />".$result ['cf_id']." ".$result ['lastname'];
}


That was it! I see the lastname now.
So, now I will work with this information to get all the fields to display, using [number], rather than ['name'].
I know I will have more questions, such as what if there are more than one record with the same lastname, etc. Should I continue with this thread or start a new one for future questions? I think this one is getting quite lengthy.

Thank you so much for your patience through this.
dianaj59 26 Apr, 2009
One more request:
Can you give me an example using this code....
<?php
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword', '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `cf_id` DESC";
$db->setQuery($sql);

/*echo '<div>$sql: '.print_r($sql, true).'</div>';*/
$results = $db->loadRowList();
/*echo '<div>$results: '.print_r($results, true).'</div>';*/
foreach ($results as $result ); {
  echo "First Name is: " .$result [5]."<br />";
  echo "Middle Name is: " .$result [6]."<br />";
  echo "Last Name is: " .$result [7];

}
}
?>


...that shows how to put it into a table format?
This is not correct, but something like:

foreach ($results as $result ); {
<table>
  <tr>
     <td>echo "First Name is: " .$result [5]."<br />";
     <td>echo "Middle Name is: " .$result [6]."<br />";
     <td>echo "Last Name is: " .$result [7];
  </tr>
  </table>


Does that make sense?
Thx.
GreyHead 27 Apr, 2009
Hi dianaj59,

You need to echo or print the html parts (or put them outside the <?php tags)
<?php
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword', '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `cf_id` DESC";
  $db->setQuery($sql);
  $results = $db->loadRowList();
  echo "<table>";
  foreach ($results as $result ); {
    echo "<tr>
      <td>First Name is: ".$result [5]."<br />
      <td>Middle Name is: ".$result [6]."<br />
      <td>Last Name is: ".$result [7]."
    </tr>";
  }
  echo "</table>";
}
?>

Bob
dianaj59 27 Apr, 2009
GREAT!
Thanks for all your help!
daniela 27 Apr, 2009
Hi,
really interesting this post
dianaj59 could you publish the last version of your code maybe explaining the all procedure?
It would be very nice
Thanks
Daniela
Max_admin 27 Apr, 2009
Hi Daniela,

Diana has posted a series of topics here recently about the search feature and I think there was a solution with all code in 2 topics of them so you can find it easily if you searched for her posts or clicked her name and choose to view her posts to see her last few topics!🙂

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dianaj59 28 Apr, 2009
In case anyone should find it hard to follow.
I'm happy to post the final result.
HTML FORM CODE: To create the search box on the page.
    <table border="0" width="100%" id="table1">
      <tr>
        <td align="center"> </td>
        <td width="119" align="center">
          <label align="right">
            <input type="text" name="keyword" size="33" class="text">
          </label>
          <input type=submit value="Search By Last Name" style="color: #6A0204; font-family: verdana; font-weight: normal; font-size:10px; background-color: #FFFFFF; float:center;" name="search">
        </td>
        <td width="30"> </td>
      </tr>
    </table>


ONSUBMIT CODE: to match the keyword and bring back all the information from the table
<?php
$db =& JFactory::getDBO();
$keyword = JRequest::getString('keyword', '', 'post');
if ( $keyword ) {
  $sql="
    SELECT *
      FROM `#__chronoforms_teacher_registration`
      WHERE `lastname` LIKE '%$keyword%'
      ORDER BY `cf_id` DESC";
$db->setQuery($sql);
/*echo '<div>$sql: '.print_r($sql, true).'</div>';*/
$results = $db->loadRowList();
/*echo '<div>$results: '.print_r($results, true).'</div>';*/
foreach ($results as $result ); {

  echo "First Name is: " .$result [5]."<br />";
  echo "Middle Name is: " .$result [6]."<br />";
  echo "Last Name is: " .$result [7]."<br />";
  echo "Date of Birth is: " .$result [8]."<br />";
  echo "Address: " .$result [9]."<br />";
  echo "City is: " .$result [10]."<br />";
  echo "State is: " .$result [11]."<br />";
  echo "Zip is: " .$result [12];

  }

}
?>


Good Luck to All and thank you Greyhead and Max!!
Max_admin 30 Apr, 2009
Thanks Diana!🙂

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jmarian1 24 Nov, 2009
Hi, I do have the same problem also and I can't find any answers here in the forum. I am using Chronoforms and I created a search button to search for any keyword in my table. I wanted to show the result of the search on the same page after the user click the submit button but it doesn't show anything.

My HTML code:

    <table border="0" width="100%" id="table1">
      <tr>
        <td align="center"> </td>
        <td width="119" align="center">
          <label align="right">
            <input type="text" name="keyword" size="33" class="text">
          </label>
          <input type=submit value="Search" style="color: #6A0204; font-family: verdana; font-weight: normal; font-size:10px; background-color: #FFFFFF; float:center;" name="searchbutton">
        </td>
        <td width="30"> </td>
      </tr>
    </table>


{result should be line up on the same page after the button is click}
but it doesn't show anything although it sends me an email about the search.

Here is my query:

<?php
$search_array = array('agencyname'); 
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>



Please help. Thanks.
GreyHead 24 Nov, 2009
Hi jmarian1,

I'm really not sure what this code is doing. Where do you have the 'query' bit? Are you actually using ChronoConnectivity (where this code might work). If you are using it in ChronoForms then you need the rest of the MySQL query and some code to display ther results.

Bob
jmarian1 24 Nov, 2009
Hi Bob, sorry about that. I wanted to use Chronoconnectivity but I don't know how to show it on the frontend. Is there a tutorial how to do it like the Chronoform that can pull from the article using {chronoform}{/chronoform}? I just wanted to know how can I show it on the frontend or should I post this question on the ChronoConnectivity then I should be fine. Thanks.
jmarian1 24 Nov, 2009
Sorry for the confusion. I figure out how to view it in the frontend and I post a new topic in ChronoConnectivity because I have some issue. Thanks.
mdsmif 14 Nov, 2010
Thanks in advance for any response.

I know this is an old subject. I am totally new at this. I am on the last part of my project.

Goal:

I created a database with patient information. I need the patients to be able to retrieve the information by search using first name, last name and date of birth. I want to display the results on a web page in my browser for confirmation. The confirmed data needs to be submitted back to me so I know the data collected was correct.

Any assistance would be appreciated. I have tried the various tutorials and searching. This post is the closest I have seen to what I actually need.

Again thanks for any help.
mdsmif 14 Nov, 2010
FYI: I am using the same code as Diana. However, I get an error message.


Warning: Invalid argument supplied for foreach() in F:\xampp\htdocs\sli\components\com_chronocontact\libraries\customcode.php(64) : eval()'d code on line 14
First Name is:
Middle Name is:
Last Name is:
Date of Birth is:
Address:
City is:
State is:
Zip is:

Thanks again.
GreyHead 17 Nov, 2010
Hi mdsmif,

It looks as though you may have spaces in some of your input names. These will casue this error. Please replace any spaced with underscores (or join the words up) - first_name or firstname.

You'll need to rename the database table columns to match then refresh the DB Connection (see below).

Bob

Note: You need to refresh the DB Connection after any changes to database column names. In the Form Editor click the DB Connection tab and set the Connection to 'No'. Click the 'Apply icon in the toolbar to save the form, open the DB Connection tab, set the Connection back to 'Yes' and re-save the form. This will refresh the copy of the table information that ChronoForms uses.
This topic is locked and no more replies can be posted.