Jump to content

How would I add a else statement to this?


Gayner

Recommended Posts

This is my code and Im trying to add a else statement that says "No Results found"

 

while ($row = $DB->fetch_row())
	{
		$cur_to = stripslashes($row['receiver_id']); 
		$cur_amount = stripslashes($row['amount']); 
		$cur_time = $row['date_time']; 
		$cur_msg = $row['message']; 
		$row['to_desktop']   = $row['to_desktop']   ? '<img src='.$row['to_desktop'].'>'   : '';
		$receiver_name = '<a href=?showuser='.trim($row['sender_id']).'>' . $row['receiver_name'] . $row['to_desktop'] . '</a>'; 
		$sender_name = $row['sender_name']; 
		$cur_to_id = $row['to_id']; 
$cur_type = $row['action']; 

($row['action']=="Cash Transfer")? $cur_type = '<i>' . $row['action'] . '</i>':"";
($row['action']=="Purchased Rainbow Orb")? $cur_type = "<b>Purchased</b> -> <font color=#0000FF>R</font><font color=#1700E8>a</font><font color=#2E00D1>i</font><font color=#4600B9>n</font><font color=#5D00A2>b</font><font color=#74008B>o</font><font color=#8B0074>w</font><font color=#A2005D> </font><font color=#B90046>O</font><font color=#D1002E>r</font><font color=#E80017>b</font>":"";
($row['receiver_name']=="Forum Store")? $receiver_name = '' . '<font color=red>Forum Store</font>' . '':"";
		   
$row['from_desktop']  = $row['from_desktop']   ? '<img src='.$row['from_desktop'].'>'   :";
}

 

 

How would I do that if there's no IF?

You would do it long before you get to that piece of code. A typical SELECT query (using the mysql_* standard extension) should look like....

 

if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
        while ($row = mysql_fetch_assoc($result)) {
            // display results.
        }
    } else {
        // No results found.
    }
} else {
    // query failed.
}

You would do it long before you get to that piece of code. A typical SELECT query (using the mysql_* standard extension) should look like....

 

if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
        while ($row = mysql_fetch_assoc($result)) {
            // display results.
        }
    } else {
        // No results found.
    }
} else {
    // query failed.
}

 

The problem is i have it in swich cases.. there's no were I can put a else and it works anywere I put it it brings up error.

switch ($global) {
    case "global":
        $DB->query("SELECT cl.*, f.desktop AS from_desktop, t.desktop AS to_desktop
FROM ibf_logs AS cl
INNER JOIN ibf_members AS f ON f.id = cl.receiver_id
INNER JOIN ibf_members AS t ON t.id = cl.sender_id
ORDER By date_time
DESC LIMIT 50");

	break;
    case "bar":
        echo "i is bar";
        break;
   default:
       $DB->query("SELECT cl.*, f.desktop AS from_desktop, t.desktop AS to_desktop
FROM ibf_logs AS cl
INNER JOIN ibf_members AS f ON f.id = cl.receiver_id
INNER JOIN ibf_members AS t ON t.id = cl.sender_id
WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month' && year = '$year' or sender_id = {$ibforums->member["id"]} && month = '$month' && year = '$year' ORDER By date_time
DESC");

 

Can u take a look please?

I tried this:

 

if ($DB->query("SELECT cl.*, f.desktop AS from_desktop, t.desktop AS to_desktop
FROM ibf_logs AS cl
INNER JOIN ibf_members AS f ON f.id = cl.receiver_id
INNER JOIN ibf_members AS t ON t.id = cl.sender_id
WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month' && year = '$year' or sender_id = {$ibforums->member["id"]} && month = '$month' && year = '$year' ORDER By date_time
DESC"));
else {
  $this->output .= '<td align=center>You</td>';
  $this->output .= '<td align=center>Have</td>';
  $this->output .= '<td align=center>No</td>';
  $this->output .= '<td align=center>Forum</td>';
  $this->output .= '<td align=center>Cash</td>';
  $this->output .= '<td align=center>Logs</td>';
}

 

But that's not working...

Did you even look at my first reply?

 

Yea i and I put the if in there it does NOT Work. it gives error cause there's no IF that it's calling..

 

Your reply doesn't even matter cause the query works and pulls up ibf logs perfectly so your missing something not me.

Did you even look at my first reply?

 

Yea i and I put the if in there it does NOT Work. it gives error cause there's no IF that it's calling..

 

Your reply doesn't even matter cause the query works and pulls up ibf logs perfectly so your missing something not me.

 

I'm not missing anything. You sir, are on your own.

Did you even look at my first reply?

 

Yea i and I put the if in there it does NOT Work. it gives error cause there's no IF that it's calling..

 

Your reply doesn't even matter cause the query works and pulls up ibf logs perfectly so your missing something not me.

 

I'm not missing anything. You sir, are on your own.

 

And theres 5000 Other people  here that will actually help :)

Did you even look at my first reply?

 

Yea i and I put the if in there it does NOT Work. it gives error cause there's no IF that it's calling..

 

Your reply doesn't even matter cause the query works and pulls up ibf logs perfectly so your missing something not me.

 

I'm not missing anything. You sir, are on your own.

 

And theres 5000 Other people  here that will actually help :)

 

Yeah, if your lucky. Thing is, I did help, you just didn't bother reading my reply properly. Do you think other people are also going to want to waste there time replying to someone who doesn't bother reading replies properly?

Did you even look at my first reply?

 

Yea i and I put the if in there it does NOT Work. it gives error cause there's no IF that it's calling..

 

Your reply doesn't even matter cause the query works and pulls up ibf logs perfectly so your missing something not me.

 

I'm not missing anything. You sir, are on your own.

 

And theres 5000 Other people  here that will actually help :)

 

Yeah, if your lucky. Thing is, I did help, you just didn't bother reading my reply properly. Do you think other people are also going to want to waste there time replying to someone who doesn't bother reading replies properly?

 

LoL buddy, i read your reply just fine...

 

I even tryed it and the

 

if($DB->query("SELECT cl.*, f.desktop AS from_desktop, t.desktop AS to_desktop

FROM ibf_logs AS cl

INNER JOIN ibf_members AS f ON f.id = cl.receiver_id

INNER JOIN ibf_members AS t ON t.id = cl.sender_id

WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month' && year = '$year' or sender_id = {$ibforums->member["id"]} && month = '$month' && year = '$year' ORDER By date_time

DESC"));

else (

echo "no result"

}

 

that doesn't work so whatever ur telling me is a lie

Read the reply again.

 

You need to check if there where any results returned!!!

 

Your code isn't even syntactically correct.

 

Another example, this time using your code. (I'm not sure why Im bothering)

 

$sql = "
SELECT cl.*, f.desktop AS from_desktop, t.desktop AS to_desktop
FROM ibf_logs AS cl
INNER JOIN ibf_members AS f ON f.id = cl.receiver_id
INNER JOIN ibf_members AS t ON t.id = cl.sender_id
WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month'
&& year = '$year' or sender_id = {$ibforums->member["id"]}
&& month = '$month' && year = '$year'
ORDER By date_time DESC
";

if($DB->query($sql)) {
    if ($DB->num_rows($result)) { //<-- YOU will need to look this method up seeing as your not using the standard mysql_* extension.
        // here you can display your results
    } else {
        echo "no result"
    }
} else {
    // your query failed
}

Read the reply again.

 

You need to check if there where any results returned!!!

 

Your code isn't even syntactically correct.

 

Another example, this time using your code. (I'm not sure why Im bothering)

 

$sql = "
SELECT cl.*, f.desktop AS from_desktop, t.desktop AS to_desktop
FROM ibf_logs AS cl
INNER JOIN ibf_members AS f ON f.id = cl.receiver_id
INNER JOIN ibf_members AS t ON t.id = cl.sender_id
WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month'
&& year = '$year' or sender_id = {$ibforums->member["id"]}
&& month = '$month' && year = '$year'
ORDER By date_time DESC
";

if($DB->query($sql)) {
    if ($DB->num_rows($result)) { //<-- YOU will need to look this method up seeing as your not using the standard mysql_* extension.
        // here you can display your results
    } else {
        echo "no result"
    }
} else {
    // your query failed
}

 

There u go!

 

Thanks that's the kinda of help i wanted

 

Love - Gayner

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.