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];
 }

Edited by barryflood22
Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.