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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.