Jump to content

if statement not working


harkly

Recommended Posts

I am trying to check a table and determine if it is empty, for some reason I cannot get it to work. I have really dumbed down the code for myself but still can't figure out why it isn't working.

 

Right now my table is all set to NULL, I have made changes to 0 and to 1 but to no avail.

 

 

<?php 
   include('library/login.php'); 
   login(); 
   mysql_select_db('test'); 

$sql = mysql_query("SELECT * FROM music WHERE userId = 'test'"); 
$results = mysql_fetch_array( $sql ); 

  if ($results == NULL) 
    { 
      echo "Empty  n";   
    } 
  else 
    { 
      echo "Not Empty n"; 
    } 
     
?> 

 

Perhaps this is not the best way to approach this??

 

Can someone help?

Link to comment
Share on other sites

Tried that and wasn't able to get that to work either I always get this output, "1 Rows ", regardless if there is a valid userID or if the info is set to Null, 0 or 1.

 

<?php

 

  include('library/login.php');

  login();

  mysql_select_db('test');

 

$result = mysql_query("SELECT * FROM music WHERE userId = 'test'") or die(mysql_error());;

$num_rows = mysql_num_rows($result);

 

echo "$num_rows Rows\n";

 

?>

 

 

 

What I am trying to do is determine if there is any info in the table under the userID and if so one set of code will run, if not than another set of code will run.

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.