TRI0N Posted February 17, 2007 Share Posted February 17, 2007 Okay installed the latest PHP for development needs and for some reason this code does not work. Any help will be very much useful. Simple call to MySQL Database by UserID to pull the owner (Manager) of the Event (event table). Pulls the info fine if there is a match but will not display the "None" when there is no match. <?php $manager = $_SESSION["userid"] ; // Database Connection mysql_connect("$dbhost","$dbuser","$dbpasswd") ; // Database Selection mysql_select_db("$dbname") ; // Extract Data $result1 = mysql_query("select distinct * from events WHERE (managerid = '$manager')") ; while($row = mysql_fetch_row($result1)) { $event_id = $row[0] ; if ($row[2] == "" || $row[2] == " ") { echo "<font color=#800000>None</font>" ; }else{ echo "<font color=#800000>›</font> <a href=\"./\">".$row[2]."</a>" ; } } ?> Thanks ahead of time, TRI0N Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/ Share on other sites More sharing options...
TRI0N Posted February 17, 2007 Author Share Posted February 17, 2007 Also I have tried to reverse this with the following code with no luck. <?php if ($row[2] != "") { echo "<font color=#800000>›</font> <a href=\"./\">".$row[2]."</a>" ; }else{ echo "<font color=#800000>None</font>" ; } } ?> Did something change between PHP 4.X and 5 that effects how this is handled? Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/#findComment-187549 Share on other sites More sharing options...
Greaser9780 Posted February 17, 2007 Share Posted February 17, 2007 Try changing this: $result1 = mysql_query("select distinct * from events WHERE (managerid = '$manager')") ; while($row = mysql_fetch_row($result1)) { $event_id = $row[0] ; if ($row[2] == "" || $row[2] == " ") { To this: $result1 = mysql_query("select distinct * from events WHERE managerid = '$manager'") ; while($row = mysql_fetch_row($result1)) { $event_id = $row[0] ; if ($row[2] == "") || ($row[2] == " ") { I am not superb with if statements but try it out Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/#findComment-187550 Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 well I dont know if this is wrong but o right its a function if($row[2] == 0) echo "none"; mayb? Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/#findComment-187553 Share on other sites More sharing options...
TRI0N Posted February 17, 2007 Author Share Posted February 17, 2007 if ($row[2] == "") || ($row[2] == " ") { Causes the page not to load. if ($row[2] == "" || $row[2] == " ") { But this format appears to work just fine. But still it doesn't show Non if $row[2] is blank. Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/#findComment-187559 Share on other sites More sharing options...
TRI0N Posted February 17, 2007 Author Share Posted February 17, 2007 if ($row[2] == 0) { Didn't do it. Not sure how it would be 0 if there is not match. $row[2] is should either be blank (null) or say "Paso Robles City Championship" So since UserID does find a match for a manager with the same ID it displays that even correctly. But I'm just baffeled why it doesn't say None when the user is logged out and the UserID is blank (null) since it doesn't exist. Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/#findComment-187566 Share on other sites More sharing options...
JasonLewis Posted February 17, 2007 Share Posted February 17, 2007 try this: $result1 = mysql_query("select distinct * from events WHERE (managerid = '$manager')") ; if(mysql_num_rows($result1) == 0){ echo "No matches for that ID."; }else{ while($row = mysql_fetch_row($result1)) { $event_id = $row[0] ; echo "<font color=#800000>›</font> <a href=\"./\">".$row[2]."</a>" ; } } Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/#findComment-187569 Share on other sites More sharing options...
TRI0N Posted February 17, 2007 Author Share Posted February 17, 2007 Most Excellent! I see it seems that you need to validate your querys now in PHP 5.X version. I've noticed a lot of things that need to be done that where not needed in 4.X but I'm sure it all got to do with stability. Thank for the fix ProjectFear and thanks for the help others offered. Link to comment https://forums.phpfreaks.com/topic/38970-php-521-and-mysql/#findComment-187579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.