I am trying to create a PHP script where text is displayed if the MySQL row id=1 has an entry of 1 in the value field and no text is shown if it has a different value. The script I wrote so far doesn’t seem to work:
<?php
// connect to the database
include('connect-db.php');
?>
<?php $result = mysql_query("SELECT * FROM Cups WHERE id='1'"); if
($row_queryname['value'] == '1') {?>
Display text here.
<?php }?>
I am quite new at this so any help would be greatly appreciated!
Thanks.
You need to use one of the “fetch” functions to actually get a row after you make a query. Since you haven’t specified any field names, I’m going to use
mysql_fetch_assoc():mysql_fetch_assoc()gets an associative array that represents a result row, where the array keys are the field names.Note: This example does not include any error checking.