barryflood22 Posted November 13, 2013 Share Posted November 13, 2013 (edited) 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]; } Edited November 13, 2013 by barryflood22 Quote Link to comment 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]; } Quote Link to comment 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 Quote Link to comment 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! '; } Quote Link to comment 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.