laPistola Posted November 14, 2008 Share Posted November 14, 2008 <?php require_once('Connections/bedroomBlogsDB.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if (isset($_SESSION['MM_Username'])) { // get logged in member $colname_memberRS = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_memberRS = $_SESSION['MM_Username']; } mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_memberRS = sprintf("SELECT id FROM members WHERE username = %s", GetSQLValueString($colname_memberRS, "text")); $memberRS = mysql_query($query_memberRS, $bedroomBlogsDB) or die(mysql_error()); $row_memberRS = mysql_fetch_assoc($memberRS); $totalRows_memberRS = mysql_num_rows($memberRS); $getUID = $row_memberRS['id']; // logged in members UID mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_messagesRS = "SELECT `to`, `sent` FROM messages WHERE (`to` = '".$getUID."' AND status = '0')"; $messagesRS = mysql_query($query_messagesRS, $bedroomBlogsDB) or die(mysql_error()); $row_messagesRS = mysql_fetch_assoc($messagesRS); $totalRows_messagesRS = mysql_num_rows($messagesRS); $mFromUID = $row_messagesRS['sent']; mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_messageFromRS = "SELECT username FROM members WHERE id = '".$mFromUID."'"; $messageFromRS = mysql_query($query_messageFromRS, $bedroomBlogsDB) or die(mysql_error()); $row_messageFromRS = mysql_fetch_assoc($messageFromRS); $totalRows_messageFromRS = mysql_num_rows($messageFromRS); $mFromUN = $row_messageFromRS['username']; mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_friendshipRequestsRS = "SELECT uid FROM friends_list WHERE (fid = '".$getUID."' AND status = '0')" ; $friendshipRequestsRS = mysql_query($query_friendshipRequestsRS, $bedroomBlogsDB) or die(mysql_error()); $row_friendshipRequestsRS = mysql_fetch_assoc($friendshipRequestsRS); $totalRows_friendshipRequestsRS = mysql_num_rows($friendshipRequestsRS); $rfFromUID = $row_friendshipRequestsRS['uid']; mysql_select_db($database_bedroomBlogsDB, $bedroomBlogsDB); $query_rfMemberRS = "SELECT username FROM members WHERE id = '".$rfFromUID."'"; $rfMemberRS = mysql_query($query_rfMemberRS, $bedroomBlogsDB) or die(mysql_error()); $row_rfMemberRS = mysql_fetch_assoc($rfMemberRS); $totalRows_rfMemberRS = mysql_num_rows($rfMemberRS); $rfUN = $row_rfMemberRS['username']; $notiF = '-1'; // This bit function notiF() { $trM = $totalRows_messagesRS; $trRF = $totalRows_friendshipRequestsRS; if (($trM>0) && ($trRF>0)) { return("<a href='friendConfirm.php'><ima src='images/notiFrf.png' alt='click to view' /></a> x".$totalRows_friendshipRequestsRS." <a href='inbox.php'><img src='images/notiFm.png' alt='Click to view' /></a> x".$totalRows_messagesRS); } else if (($trM>1) && ($trRF<1)) { return("<a href='inbox.php'>You have ".$totalRows_messagesRS." messages <img src='images/notiFm.png' alt='Click to view' /></a>"); } else if (($trM==1) && ($trRF<1)) { return("<a href='inbox.php'>".substr($mFromUN,15,0)." has sent you a message <img src='images/notiFm.png' alt='Click to view' /></a>"); } else if (($trM<1) && ($trRF==1)) { // This one should be true ?? return("<a href='friendConfirm.php'>".substr($rfUN,15,0)." has requested your friendship <img src='images/notiFrf.png' alt='Click to view' /></a>"); } else if (($trM<1) && ($trRF>1)) { return("<a href='friendConfirm.php'>You have ".$totalRows_friendshipRequestsRS." waiting friends requests"); } else { return("none"); } } $notiF = notiF(); // To this bit mysql_free_result($memberRS); mysql_free_result($messagesRS); mysql_free_result($messageFromRS); mysql_free_result($rfMemberRS); mysql_free_result($friendshipRequestsRS); } else { // else to isset line 35 $notiF = ' '; } ?> Hello i have marked places in the above code in comments to show you which bit im talking about (// This bit) and (// This should be true) Basicly every time the page is loaded the var is echoing the word none which is the else to function, now i have triple checked that $totalRows_messagesRS is o and $totalRows_friendshipRequestsRS is 1 but the else if that should read true isn't?? the MySQL server is 5.0.67 Any ideas?? Link to comment https://forums.phpfreaks.com/topic/132748-solved-ballon-if-that-should-read-true-dont/ Share on other sites More sharing options...
flyhoney Posted November 14, 2008 Share Posted November 14, 2008 I stared at this for awhile and I did not see any problems. Try echoing the values of $trM and $trRF at the beginning and end of the function. Link to comment https://forums.phpfreaks.com/topic/132748-solved-ballon-if-that-should-read-true-dont/#findComment-690354 Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 No need to. They're undefined. $totalRows_messagesRS and $totalRows_friendshipRequestsRS are not visible within function. Either make these two variables global, or pass them to your function via arguments. Link to comment https://forums.phpfreaks.com/topic/132748-solved-ballon-if-that-should-read-true-dont/#findComment-690359 Share on other sites More sharing options...
flyhoney Posted November 14, 2008 Share Posted November 14, 2008 Man, I completely missed that! You are also referencing other variables that are out of scope: $mFromUN, $rfUN. You need to either pass these to the function or declare them as global. Link to comment https://forums.phpfreaks.com/topic/132748-solved-ballon-if-that-should-read-true-dont/#findComment-690362 Share on other sites More sharing options...
laPistola Posted November 15, 2008 Author Share Posted November 15, 2008 of cause there inside the first if. dope, cheers ill have a play Link to comment https://forums.phpfreaks.com/topic/132748-solved-ballon-if-that-should-read-true-dont/#findComment-690715 Share on other sites More sharing options...
laPistola Posted November 15, 2008 Author Share Posted November 15, 2008 Pass vars and its works however can you not use vars in return()? Link to comment https://forums.phpfreaks.com/topic/132748-solved-ballon-if-that-should-read-true-dont/#findComment-690723 Share on other sites More sharing options...
laPistola Posted November 15, 2008 Author Share Posted November 15, 2008 dont answer that i no the answer, you have to wrap vars in {} on return... Thank you for your time Link to comment https://forums.phpfreaks.com/topic/132748-solved-ballon-if-that-should-read-true-dont/#findComment-690724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.