Jump to content

PHP 5.2.1 and MySQL


TRI0N

Recommended Posts

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

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

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

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

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

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

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.