Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

query a database

I am trying to query the datbase. What I am trying to do is to query the database and see if the field value of submiteddate is Null or empty then print out in the table field "Not completed. If there is any other record there, Prin oput "Complted"
The problem is that my code is not working and I am not sure about the right syntax

Here is the code

 <td height="18" width="64"><h3><a  href="site.index.php">Link</a></h3></td>
          </tr>
      </table>
    </div></td>
    <td><div align="center">
    <?php $db = mysql_connect('localhost', 'root', 'password') or die("Couldn't connect to the database.");
            mysql_select_db('wde') or die("Couldn't select the database");
            $stat = mysql_query("SELECT count(uid) FROM wde_users where submitdate =''") or die("Couldn't query the user-database for  Values.");
            $status = mysql_result($stat,0);
            if (!$status) {
            echo "Not Completed";
            }else{
            echo "Completed"
            }?>
      
   
   
    </div></td>
    <td><div align="center"></div></td>
  </tr>

Thanks in advance
0
syedasimmeesaq
Asked:
syedasimmeesaq
  • 4
  • 3
  • 3
2 Solutions
 
steelseth12Commented:
<td height="18" width="64"><h3><a  href="site.index.php">Link</a></h3></td>
          </tr>
      </table>
    </div></td>
    <td><div align="center">
    <?php $db = mysql_connect('localhost', 'root', 'password') or die("Couldn't connect to the database.");
           
                mysql_select_db('wde') or die("Couldn't select the database");
           
                $stat = mysql_query("SELECT * FROM wde_users where submitdate ='' OR submitdate IS NULL") or die("Couldn't query the user-database for  Values.");
           
                $status = mysql_num_rows($stat);
           
                if ($status) {
           
                echo "Not Completed";
           
                }else{
           
                echo "Completed"
           
                }?>
     
   
   
    </div></td>
    <td><div align="center"></div></td>
  </tr>
0
 
ZylochCommented:
Depending on how your database field is set up, you may be wanting something like

SELECT uid FROM wde_users where submitdate = '' OR submitdate IS NULL

Then, you would do something like

$num_records = mysql_num_rows($stat);
if ($num_records > 0) {
    echo 'Not completed';
} else {
    echo 'Completed';
}
0
 
ZylochCommented:
Hm, a bit too late. Sorry.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
steelseth12Commented:
This will return Not completed if any row of has an empty or null submitdate column

Is this what you are looking for or do you want to search in a specific set ?
0
 
steelseth12Commented:
ive been late my whole life :)
0
 
syedasimmeesaqAuthor Commented:
when I used above codes..it just shows me a blank screen
Thanks
0
 
steelseth12Commented:
forgot a ;

try

<td height="18" width="64"><h3><a  href="site.index.php">Link</a></h3></td>
          </tr>
      </table>
    </div></td>
    <td><div align="center">
    <?php $db = mysql_connect('localhost', 'root', 'password') or die("Couldn't connect to the database.");
           
                mysql_select_db('wde') or die("Couldn't select the database");
           
                $stat = mysql_query("SELECT * FROM wde_users where submitdate ='' OR submitdate IS NULL") or die("Couldn't query the user-database for  Values.");
           
                $status = mysql_num_rows($stat);
           
                if ($status) {
           
                echo "Not Completed";
           
                }else{
           
                echo "Completed";
           
                }?>
     
   
   
    </div></td>
    <td><div align="center"></div></td>
  </tr>


also put on top of your page
error_reporting(E_ALL);
ini_set("display_errors","on");

to see if it gives out any errors
0
 
syedasimmeesaqAuthor Commented:
steelseth12 I worked perfect. Is there any way to get "Completed" in red fonts.
Thanks for you help.
0
 
ZylochCommented:
Just echo it in red, i.e.

echo '<span style="color: red;">Completed</span>';
0
 
syedasimmeesaqAuthor Commented:
Thank you guys
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now