-
Filter recordset
I have a table with 2 fields. I want to display a recordset on a page that displays the results of field 2. That is easy, I have done that, however I want to change the result to display the value from field 2 only if field 1 contains a certain value.
My recordset code looks like this:
<?php echo $row_Recordset1['field2']; ?></p>
This is probably really easy but I am having some trouble.
Thanks,
Dave
-
Try something like this:
PHP Code:
<?php
if($row_Recordset1['field1'] == '**ENTER_CERTAIN_VALUE**') {
echo $row_Recordset1['field2']."</p>";
}
?>
HTH:)
-
The other approach to this would be to do it in your Select statement.
PHP Code:
$value="selection criteria";
$row = mysql_query("SELECT field2 FROM mytable WHERE field1=$value");
This way you only get the records that match the required selection criteria
-
Thanks, that worked good. What I need to do now is display a different set of values from the same table. One line shows the results of field 2 when field 1 is equal to one value. The next line will show the results of field 2 when field 1 is equal to a different value. My thought is that I would do this:
Code:
<?php
if($row_Recordset1['department'] == 'Childrens Church') {
echo $row_Recordset1['names']."</p>";
}
?>
<?php
if($row_Recordset1['department'] == 'Welcome Ministry') {
echo $row_Recordset1['names']."</p>";
}
?>
This is not working for some reason?
-
Try this
PHP Code:
<?php
if($row_Recordset1['department'] == 'Childrens Church') {
echo $row_Recordset1['names']."</p>";
}else if($row_Recordset1['department'] == 'Welcome Ministry') {
echo $row_Recordset1['names']."</p>";
}
?>
-
It is still only showing the one set of records "Childrens Church".
-
This should be working ...
PHP Code:
<?php
if($row_Recordset1['department'] == 'Childrens Church') {
echo $row_Recordset2['names']."</p>";
}
if($row_Recordset2['department'] == 'Welcome Ministry') {
echo $row_Recordset1['names']."</p>";
}
?>
is it not?
-
I noticed in th reply you RecordSet1 & RecordSet2. How should I create those record sets?
-
I meant this:
PHP Code:
<?php
if($row_Recordset1['department'] == 'Childrens Church') {
echo $row_Recordset1['names']."</p>";
}
if($row_Recordset1['department'] == 'Welcome Ministry') {
echo $row_Recordset1['names2']."</p>";
}
?>
... changing names2 to whatever field you want to have displayed.
-
Yes, that is working now, one thing that I noticed I had not done is, I didn't have the dynamic text inside a repeat region, so it was just displaying the first result.
Thanks so much for your help,
Dave
-
I thought that it was working, but it still doesn't seem to be functioning. Basically this is what I am looking for the result to look like. I will have headings that are not dynamic text.
Nursery: [NAME(s) from Table where DEPARTMENT in equal to Nursery]
Wee Church: [NAME(s) from Table where DEPARTMENT in equal to Wee Church]
And so on...
When I have the code that is referenced in the last post, inside a repeat region it repeats the whole entire table for every record. When I leave out a repeat region it doesn't return any results at all.
Below is the code that I a have when it repeats everything for each record.
Code:
<?php do { ?>
<strong>Nursery</strong><br />
<?php
if($row_Recordset1['department'] == 'Nursery') {
echo $row_Recordset1['names']."</p>";
}?>
<br />
<strong>Baby Ministers</strong><br />
<?php
if($row_Recordset1['department'] == 'Baby Minister') {
echo $row_Recordset1['names']."</p>";
}
?>
<br />
<strong>Pre Wee Church</strong><br />
<?php
if($row_Recordset1['department'] == 'Pre Wee Church') {
echo $row_Recordset1['names']."</p>";
}
?>
<br />
<strong>Wee Church</strong><br />
<?php
if($row_Recordset1['department'] == 'Wee Church') {
echo $row_Recordset1['names']."</p>";
}
?>
<br />
<strong>Childrens Church</strong><br />
<?php
if($row_Recordset1['department'] == 'Childrens Church') {
echo $row_Recordset1['names']."</p>";
}
?>
<br />
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
Thanks so much for your input.
-
What do you mean by 'repeat region'? Do you mean you only want one result?
-
I do have more than one name under each heading, I have found that if I want to display more than just the first result on the page I need to have it inside a 'repeat region' (this could be Dreamweaver term). I may be mistaken about this, but that is usually how I have gotten that to work.
To eliminate any confusion I am going to explain exactly what I am trying to do. This is for a schedule of people serving on a particular day. Just to pick a day I will choose Oct 4.
I have a table called 'Oct 4' that has two fields 'department' and 'name'. There are like 12 different departments and each has at least 2 names of people that are serving in that department on any particular day.
The simple way to do this would be to just display department & name for each record, sort it by the department name, and list them down the page. However if there is multiple people serving in one department I only want to show the department heading once, then the names. I don't really need to get the department headings from the database, those can just be on the page itself.
This is the code below id what I am using for one section of this 'Childrens Ministry'. It works, except it is only showing one result under one heading. If I put this inside a repeat region, it will repeat the whole entire list of headings, including the next record in the list.
Code:
<div align="center"><strong>CHILDREN</strong><br />
Nursery: <br />
<?php
if($row_Recordset1['department'] == 'Nursery') {
echo $row_Recordset1['names']."</p>";
}?>
<br />
Baby Ministers:<br />
<?php
if($row_Recordset1['department'] == 'Baby Minister') {
echo $row_Recordset1['names']."</p>";
}?>
<br />
Pre Wee Church<br />
<?php
if($row_Recordset1['department'] == 'Pre Wee Church') {
echo $row_Recordset1['names']."</p>";
}?>
<br />
Wee Church<br />
<?php
if($row_Recordset1['department'] == 'Wee Church') {
echo $row_Recordset1['names']."</p>";
}?>
<br />
Childrens Church<br />
<?php
if($row_Recordset1['department'] == 'Childrens Church') {
echo $row_Recordset1['names']."</p>";
}?>
</div>
This seems like it should be working, it is weird that it will not. To give a better idea here is a couple links to help visualize the results I am getting.
Withou the 'repeat region': http://www.living-waters.net/schedul...put/date01.php
With the 'repeat region': http://www.living-waters.net/schedul...e01_repeat.php
-
Nevermind on trying to get this approach to work. I have decided to go a slightly different way. I am going to have all the date (dept, names, dates) and just call those out with a simple search page, rather than trying to display them all at once.
Thanks for everyone's insight.