Jump to content

if and else


barryflood22

Recommended Posts

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

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.