Friday, 15 July 2011

php - How to exclude data if value is set to 0? -



php - How to exclude data if value is set to 0? -

i trying parse info mysql database, have column calls is_approved , value either 0 or 1 (0 no, 1 yes)

i want approved echoed

how can this?

<?php // connect mysql $link = mysql_connect( 'localhost', 'username', 'password' ); if ( !$link ) { die( 'could not connect: ' . mysql_error() ); } // select info base of operations $db = mysql_select_db( 'database', $link ); if ( !$db ) { die ( 'error selecting database \'database\' : ' . mysql_error() ); } // fetch info $query = " select * prayer order created_at desc"; $result = mysql_query( $query ); // good? if ( !$result ) { // nope $message = 'invalid query: ' . mysql_error() . "\n"; $message .= 'whole query: ' . $query; die( $message ); } // print out rows while ( $row = mysql_fetch_assoc( $result ) ) { //echo json_encode($row); echo 'name: '.$row['first_name'] . ' ' . $row['last_name'] . ' <br>gypsy name: ' .$row['gypsy_name'].'<br>veetsa: ' .$row['veetsa'].'<br> location: ' .$row['location'].'<br>' .$row['created_at'].'<br>' .$row['content'] . "<hr>"; } // close connection mysql_close($link); ?>

the plan spit out json can utilize on server

just add together where clause query:

select * prayer is_approved = 1 order created_at desc

php mysql json

No comments:

Post a Comment