Jump to content

Bypass Select statement when empty.


cyprus

Recommended Posts

How can I bypass the code below if my $fields and $where have not been executed yet? The first time the page appears its empty. Thanks

$username="root";
$password="";
$database="";
mysql_connect(localhost,$username);
$query = "SELECT $fields FROM ORDERS $where";
@mysql_select_db($database) or die( "Unable to select database");     
$result = mysql_query($query) or die('Problem with query: ' . $query . '<br>'. mysql_error());
$numrows=mysql_numrows($result);
Link to comment
https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/
Share on other sites

You could use an if statement

[code]<?php

$username="root";
$password="";
$database="";
mysql_connect(localhost,$username);

if($fields == "" || $where == "")
{
// Show the page when nothing is defined for $fields and $where
}
else
{
$query = "SELECT $fields FROM ORDERS $where";
@mysql_select_db($database) or die( "Unable to select database");   
$result = mysql_query($query) or die('Problem with query: ' . $query . '
'. mysql_error());
$numrows=mysql_numrows($result);
}

?>[/code]

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.