Jump to content

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]
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.