Gayner Posted August 28, 2009 Share Posted August 28, 2009 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? Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/ Share on other sites More sharing options...
trq Posted August 28, 2009 Share Posted August 28, 2009 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. } Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908242 Share on other sites More sharing options...
Gayner Posted August 28, 2009 Author Share Posted August 28, 2009 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? Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908672 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 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... Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908675 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 Did you even look at my first reply? Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908684 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 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. Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908687 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 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. Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908689 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 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 Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908690 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 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? Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908697 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 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 Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908699 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 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 } Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908702 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 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 Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908716 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 That is exactly the same as my first reply. Learn to learn by example, and don't be so smug when you don't understand. Accusing me of lying and 'missing something' is no way to reply to someone who is providing help. Link to comment https://forums.phpfreaks.com/topic/172259-how-would-i-add-a-else-statement-to-this/#findComment-908722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.