barryflood22 Posted November 13, 2013 Share Posted November 13, 2013 I have a piece of script below that I wrote, but I don't want it to echo both results. I only want it to techo one of them. I think if it was something like this it would work: if 'column1' is not empty then echo 'value'. im having a bit of trouble getting it to do that, please help :-( <?php $signatureslist = mysql_query("SELECT * FROM $table, $usernamestable Where $table.subscriber_id= $usernamestable.id and $table.list_id='$listid' ORDER BY subdate desc limit 20 ", $link); while ($row = mysql_fetch_assoc($signatureslist)) { echo '<li style="padding:5px 0 5px 0;"><strong class="largertext" style="color:#e6b532">'; echo $row[name]; echo ' </strong><br /><div style="margin-top:-6px">from '; echo $row[column1]; $registeredcountry = mysql_query("SELECT * FROM z1gv4_community_fields_values where user_id =" . $row[user_id] . " and field_id = " . $field_id . "", $link); while ($row2 = mysql_fetch_assoc($registeredcountry)) { echo $row2[value]; } Link to comment https://forums.phpfreaks.com/topic/283877-if-and-else/ Share on other sites More sharing options...
barryflood22 Posted November 13, 2013 Author Share Posted November 13, 2013 I may have sorted it, can you guys check this is correct? <?php $signatureslist = mysql_query("SELECT * FROM $table, $usernamestable Where $table.subscriber_id= $usernamestable.id and $table.list_id='$listid' ORDER BY subdate desc limit 20 ", $link); while ($row = mysql_fetch_assoc($signatureslist)) { echo '<li style="padding:5px 0 5px 0;"><strong class="largertext" style="color:#e6b532">'; echo $row[name]; echo ' </strong><br /><div style="margin-top:-6px">from '; $registeredcountry = mysql_query("SELECT * FROM z1gv4_community_fields_values where user_id =" . $row[user_id] . " and field_id = " . $field_id . "", $link); while ($row2 = mysql_fetch_assoc($registeredcountry)) if(empty($row['column1'])) { echo $row2[value]; } else { echo $row[column1]; } Link to comment https://forums.phpfreaks.com/topic/283877-if-and-else/#findComment-1458159 Share on other sites More sharing options...
dalecosp Posted November 14, 2013 Share Posted November 14, 2013 <?php$signatureslist = mysql_query("SELECT * FROM $table, $usernamestable Where $table.subscriber_id= $usernamestable.id and $table.list_id='$listid' ORDER BY subdate desc limit 20 ", $link); if (!$signatureslist) { //put an error handler here: maybe 'die("no result from Query!");' ?} //I'm gonna change your bracket style; you should do it as the above in JS, so let's do it in PHP too... while ($row = mysql_fetch_assoc($signatureslist)) { echo '<li style="padding:5px 0 5px 0;"><strong class="largertext" style="color:#e6b532">'; echo $row[name]; echo ' </strong><br /><div style="margin-top:-6px">from '; //Generally it's not a good idea to put a query inside a loop. If your outer loop will occur many times, that is... can this be combined with the query above?//also, why do "select *" when you're only using "column1" ? $registeredcountry = mysql_query("SELECT column1 FROM z1gv4_community_fields_values where user_id =" . $row[user_id] . " and field_id = " . $field_id . "", $link); //this looks like an error ... no block brackets after it? I'll add them: while ($row2 = mysql_fetch_assoc($registeredcountry)) { //added this one if(empty($row['column1'])) { echo $row2[value]; } else { echo $row[column1]; }}//and this one Link to comment https://forums.phpfreaks.com/topic/283877-if-and-else/#findComment-1458198 Share on other sites More sharing options...
KaiSheng Posted November 14, 2013 Share Posted November 14, 2013 just keep this in mind; every 1 bracket you open, close 1 back. basic format starts like this: if (today=='rain') { echo 'bring umbrella'; } else if (today=='snow') { echo 'wear sweater'; } else { echo 'It is a good sunny day! '; } Link to comment https://forums.phpfreaks.com/topic/283877-if-and-else/#findComment-1458199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.