{Surname}, {Firstname} {Username} {Art} {Drama} {Music} {ESOLa} {Numeracya} {Moari} {French} {Japanese} {ESOLb} {Literacy} {Numeracyc} {Technology} {FoodTechnology} {Graphics} {ESOLc} {Numeracyc}Footer {pagination}Where SQLI thought I could put a PHP if statement in the header section to prevent the rest from running if Username in the Search/Filter field was blank but I am doing something wrong.Any ideas?"> Preventing a complete listing when first presenting the page - Forums

Forums

Preventing a complete listing when first presenting the page

abasel 03 Mar, 2012
My current code works fine but I don't want it to list all entries. I only want it to display the results of the filter/Search so when I person first visits the page they must only see the filter/search box.

Header

<?php
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__chronoforms_form_Year8To9_options;";
$db->setQuery($query);
$result = $db->query();
$row = $db->loadRow();
$i=0;
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p><input type='text' name='Username' id='Username' value='' /> <input type='submit'
name='submit' id='submit' value='Filter' class="filter"/></p>
</td>
    <td><p><a href="index.php?option=com_chronocontact&chronoformname=form_Year8To9_options_export">Download CSV</a></p>
</td>
  </tr>
</table>
<!-- I thought I could put a PHP if statement here to prevent the rest from running if Username was blank but I am doing something wrong ->
<p> </p>

<table border="0" cellspacing="0" cellpadding="0">
<tr class="d0">
    <td width="104"><strong>Name</strong></td>
    <td width="40" align="center"><strong>ID</strong></td>
    <td width="28" align="center"><strong>Art</strong></td>
    <td width="28" align="center"><strong>Dra</strong></td>
    <td width="28" align="center"><strong>Mus</strong></td>
    <td width="28" align="center"><strong>ESO</strong></td>
    <td width="28" align="center"><strong>Num</strong></td>
    <td width="28" align="center"><strong>Mao</strong></td>
    <td width="28" align="center"><strong>Fre</strong></td>
    <td width="28" align="center"><strong>Jap</strong></td>
    <td width="28" align="center"><strong>ESO</strong></td>
    <td width="28" align="center"><strong>Lit</strong></td>
    <td width="28" align="center"><strong>Num</strong></td>
    <td width="28" align="center"><strong>Tec</strong></td>
    <td width="28" align="center"><strong>Foo</strong></td>
    <td width="28" align="center"><strong>Gra</strong></td>
    <td width="28" align="center"><strong>ESO</strong></td>
    <td width="28" align="center"><strong>Num</strong></td>
</tr>
 <tr class="d0">
    <td colspan="18"><hr></td>
  </tr>


Body

<?php
$i=$i+1;
if ($i>=2) {$i=0;}
?>
<tr class="d<?=$i;?>">
    <td>{Surname}, {Firstname}</td>
    <td align="center">{Username}</td>
    <td align="center">{Art}</td>
    <td align="center">{Drama}</td>
    <td align="center">{Music}</td>
    <td align="center">{ESOLa}</td>
    <td align="center">{Numeracya}</td>
    <td align="center">{Moari}</td>
    <td align="center">{French}</td>
    <td align="center">{Japanese}</td>
    <td align="center">{ESOLb}</td>
    <td align="center">{Literacy}</td>
    <td align="center">{Numeracyc}</td>
    <td align="center">{Technology}</td>
    <td align="center">{FoodTechnology}</td>
    <td align="center">{Graphics}</td>
    <td align="center">{ESOLc}</td>
    <td align="center">{Numeracyc}</td>
</tr>

Footer
</table>
<p> </p>

{pagination}


Where SQL
<?php
$Username = JRequest::getString('Username', '', 'post');
if ( $Username) {
echo " WHERE `Username` LIKE '%$Username%' ";
}
?>


I thought I could put a PHP if statement in the header section to prevent the rest from running if Username in the Search/Filter field was blank but I am doing something wrong.

Any ideas?
GreyHead 03 Mar, 2012
Hi abasel,

We've done this in the past by setting a WHERE clause that will return no results if the search term isn't present e.g. WHERE 'a' = 'b' or WHERE `id` = 9999999

Bob
abasel 03 Mar, 2012
Perfect, for the sake of the discussion, I add my code:

<?php
$Username = JRequest::getString('Username', '', 'post');
if ( $Username) {
echo " WHERE `Username` LIKE '%$Username%' ";
} else
{echo " WHERE `Username` = 'abc123' ";}
?>
This topic is locked and no more replies can be posted.