87dave87 Posted May 9, 2007 Share Posted May 9, 2007 Trying to show results of address details from my database. But the if statement for 'if there is no result' isnt working... its just displaying 'no recordno recordno record ' I want this to skip if there is no result (using the 'no record' as test text) Also how can I skip showing a detail, such as 'echo "$addressline2<br>";' if there is nothing in that field on the database? Mailshots from <? $query = "SELECT * FROM userfield"; $result = mysql_query($query); $num = mysql_numrows($result); print $num ?> Members </b> <p> <? $i=0; while ($i < $num) { $firstnames=mysql_result($result,$i,"field5"); $surname=mysql_result($result,$i,"field6"); $housenamenumber=mysql_result($result,$i,"field7"); $addressline1=mysql_result($result,$i,"field8"); $addressline2=mysql_result($result,$i,"field9"); $addressline3=mysql_result($result,$i,"field10"); $citycounty=mysql_result($result,$i,"field11"); $postcode=mysql_result($result,$i,"field12"); $country=mysql_result($result,$i,"field13"); if($result="") { echo "no record"; } else { echo "-- TEST --<br>"; echo "$firstnames $surname<br>"; echo "$housenamenumber $addressline1<br>"; echo "$addressline2<br>"; echo "$addressline3<br>"; echo "$citycounty<br>"; echo "$postcode<br>"; echo "$country<br>"; echo "-- TESTEND --<br>"; echo "<br>"; } $i++; } ?> </p> <? mysql_close($conn); ?> For the page click here Quote Link to comment https://forums.phpfreaks.com/topic/50628-basic-record-display-problems/ Share on other sites More sharing options...
taith Posted May 9, 2007 Share Posted May 9, 2007 <? $result = mysql_query("SELECT * FROM userfield"); while ($row=mysql_fetch_assoc($result)) { echo "-- TEST --<br>"; if(!empty($firstnames)) echo "$row[field5] $row[field6]<br>"; if(!empty($addressline1)) echo "$row[field7] $row[field8]<br>"; if(!empty($addressline2)) echo "$row[field9]<br>"; if(!empty($addressline3)) echo "$row[field10]<br>"; if(!empty($citycountry)) echo "$row[field11]<br>"; if(!empty($postcode)) echo "$row[field12]<br>"; if(!empty($country)) echo "$row[field13]<br>"; echo "-- TESTEND --<br>"; echo "<br>"; } mysql_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50628-basic-record-display-problems/#findComment-248862 Share on other sites More sharing options...
87dave87 Posted May 9, 2007 Author Share Posted May 9, 2007 where would that be placed? When I try to use it I just get: - -- TEST -- -- TESTEND -- -- TEST -- -- TESTEND -- -- TEST -- -- TESTEND -- Quote Link to comment https://forums.phpfreaks.com/topic/50628-basic-record-display-problems/#findComment-248868 Share on other sites More sharing options...
taith Posted May 9, 2007 Share Posted May 9, 2007 oops <? $result = mysql_query("SELECT * FROM userfield"); while ($row=mysql_fetch_assoc($result)) { echo "-- TEST --<br>"; if(!empty($row[field5])) echo "$row[field5] $row[field6]<br>"; if(!empty($row[field7])) echo "$row[field7] $row[field8]<br>"; if(!empty($row[field9])) echo "$row[field9]<br>"; if(!empty($row[field10])) echo "$row[field10]<br>"; if(!empty($row[field11])) echo "$row[field11]<br>"; if(!empty($row[field12])) echo "$row[field12]<br>"; if(!empty($row[field13])) echo "$row[field13]<br>"; echo "-- TESTEND --<br>"; echo "<br>"; } mysql_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50628-basic-record-display-problems/#findComment-248870 Share on other sites More sharing options...
87dave87 Posted May 9, 2007 Author Share Posted May 9, 2007 Thanks, that works great but is it possible to not check each field, and just check the whole row for no record? although they each record contains a userid and a temp field which contains 'NULL' for each record. Quote Link to comment https://forums.phpfreaks.com/topic/50628-basic-record-display-problems/#findComment-248872 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.