Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show only records that match my argument - not working.

Status
Not open for further replies.

dreamaz

Technical User
Dec 18, 2002
184
0
0
CA
Hi,

I have a field in mysql table named Resolved. I have added the following argument to my php page to show me only records that have this value set to 0. Don't want those which are resolved=1 to be shown.

<?php if ($row_GetKitt['Resolved'] == 0) { ?>

<?php do { ?>

<?php echo $row_GetKitt['KITT']; ?>

<?php } while ($row_GetKitt = mysql_fetch_assoc($GetKitt)); } ?>

I am getting everything shown on the page, including those that are marked resolved=1.

When i change <?php if ($row_GetKitt['Resolved'] == 1) { ?> i get nothing shown at all. Am I missing something here?

Any help is appreciated.

Thanks,

JR
 
First of all whats the deal with all the opeing and closing PHP tags. open ince and close once. Unless its really necessary to open and clos on evey line.

Second:
You are checking for something that has nothing in it yet, as you DO While loops is below the If statemten try this:

Code:
<?php 
 do 
  { 
     if ($row_GetKitt['Resolved'] == 0) 
      { 
          echo $row_GetKitt['KITT']; 
      }

  }while ($row_GetKitt = mysql_fetch_assoc($GetKitt)); } 

?>



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Don't use a do..while here. The if-statement will run once before any data has been fetched, and so $row_GetKitt will be uninitialized. In this case, use a while-loop:

Code:
<?php 
while ($row_GetKitt = mysql_fetch_assoc($GetKitt))
{ 
   if ($row_GetKitt['Resolved'] == 0) 
   { 
      echo $row_GetKitt['KITT']; 
   }
}
?>

Out of curiosity, why are you filtering in PHP? Why not just construct a SELECT query with a WHILE clause that selects only those records where the column Resolved is the value you want?



Want the best answers? Ask the best questions! TANSTAAFL!
 
SELECT resolved FROM bdName WHERE resolved = '0'

It's less load on a server to get only what you need from the database, rather then getting everything and using php to filter out what you want.

On the other hand, if you do need all the information, just not in this code snippet, then disregard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top