MySQL boolean type to return boolean query? - mysqli

I'm trying to see if its possible to test for a certain result specific to a boolean value in an SQL database.
if($result = $mysqli->query("SELECT * FROM `work_orders` WHERE `is_open` = '1' "))
{
show_workorder($result);
}
I would then want to execute:
#TRUE allows this to show
if($result = True){
echo "<p> No current work orders are open. Good Work !</p>\n";
return;
}
If i change database in work_orders.is_open , the boolean is 0, meaning its "not open" .. the if statement for TRUE above, still shows...
I am sure that I'm missing something.

Seems I have solved my own question:
the if statement should just test for rows that were returned or not.
if($result->num_rows == 0)
this would allow it to show if there is nothing returned. If results are returned then it will continue moving forward.

Related

how to prevent logging warning in a .get(true , false) statement to appear even though it is true and not false

I am making an application which rarely uses the terminal for output. So, I found that the logging library was a great way to help debug faulty code as supposed to the print statement.
But, for this code, specifically the .get() statement at the bottom...
def process_variables(self, argument):
data = pd.read_excel(self.url, sheet_name=self.sheet)
data = pd.concat([data.iloc[2:102], data.iloc[107:157]]).reset_index()
fb = data.loc[0:99, :].reset_index()
nfb = data.loc[100:155, :].reset_index()
return {'fb': data.loc[0:99, :].reset_index(),
'nfb': data.loc[100:155, :].reset_index(),
'bi': data.loc[np.where(data['Unnamed: 24'] != ' ')],
'uni': data.loc[np.where(data['Unnamed: 25'] != ' ')],
'fb_bi': fb.loc[np.where(fb['Unnamed: 24'] != ' ')],
'fb_uni': fb.loc[np.where(fb['Unnamed: 25'] != ' ')],
'nfb_bi': nfb.loc[np.where(nfb['Unnamed: 24'] != ' ')],
'nfb_uni': nfb.loc[np.where(nfb['Unnamed: 25'] != ' ')],
}.get(argument, f"{logging.warning(f'{argument} not found in specified variables')}")
...returns this...
output
The output returns the default argument even though the switch-case argument was successful, given that it did return the pandas Data frame.
So how can I make it so it only appears when it wasn't found, as it should if it were just a string and not a logging-string method.
Thank you for your help in advance :)
Python evaluates the arguments for the arguments to a function before it calls the function. That's why your logging function will get called regardless of the result of get(). Another thing is your f-string is probably going to evaluate to "None" every time since logging.warning() doesn't return anything, which doesn't seem like what you intended. You should just handle this with a regular if statement like
variables = {
'fb': data.loc[0:99, :].reset_index(),
...
}
if argument in variables:
return variables[argument]
else:
logging.warning(f'{argument} not found in specified variables')

Find out whether function returns true or false

I am struggling to make form validation work and it looks like the main problem is placeOrder function (other function which sit inside this functions work just fine). The function behaves in a strange way (gives alert only if the first input field (message) does not confirm to the test conditions, while if I leave the others blank it does not show alert). I was trying to find the reason for that by putting each part of the main if statement (which are divided by AND operators) in this test:
if(validateLenghtData(5, 32, form["message"], form["message_help"])) {
console.log("validation passed");
} else {
console.log("validation failed");
}
This gave me nothing because it only returns false ("validation failed") to console, while it outputs nothing if I enter valid text to the input. Where can be the bug and how can I test each part of big if statement ( like validatedZipCode(form["zipcode"], form["zipcode_help"])) in order to find out which part gives me false.
function placeOrder(form) {
// first check whether all fields are filled with valid data
// form["message"] and other simular arguments are part of form object and are passed from submit form (look it)
if (validateLenghtData(5, 32, form["message"], form["message_help"]) &&
validatedZipCode(form["zipcode"], form["zipcode_help"]) &&
validateNonEmptyField(form["date"], form["date_help"]) &&
validateNonEmptyField(form["name"], form["name_help"]) &&
validateNonEmptyField(form["phone"], form["phone_help"]) &&
validateNonEmptyField(form["email"], form["email_help"])) {
// everything is ok, submit the order to the server
form.submit();
} else {
alert ("You need to feel all fields correctly");
}
if(validateLenghtData(5, 32, form["message"], form["message_help"])) {
console.log("validation passed");
} else {
console.log("validation failed");
}
}

Can i have 2 conditions in protractor expect function? Also give me expect statement to verify whether the getText() has the expected value?

Here i want to combine the below 2 expectations into one.
expect(button.getText()).toEqual('Process Successful');
expect(button.getText().indexOf('- code 3001')).toBeGreaterThan(0);
Also whether the below statement is correct or not. I am trying to verify in the getText() whether expected value is present in the text.
expect(button.getText().indexOf('- code 3001')).toBeGreaterThan(0);
You can use expect().toContain() to verify text contained in string.
expect(button.getText()).toContain('Process Successful');
expect(button.getText()).toContain('- code 3001');
You can also do it in another way,
var buttonContainsText = button.getText().then(function(text){
return (text.indexOf('Process Successful') > -1) && (text.indexOf('- code 3001') > -1)
})
expect(buttonContainsText).toBeTruthy();

code to destroy zend session gets executed although its not allowed by if else and switch case conditions

$getId = $this->getRequest()->getParam('id'); // 1 is coming from url
$id_from_cart = 1;
if($getId != $id_from_cart) {
echo "unset session";
Zend_Session::namespaceUnset('cart');
} else {
echo "dont unset";
}
When I use $getId = 1 as a static value, its working fine but if I use $this->getRequest()->getParam('id') as its value which is also 1 then although it goes in else condition in both the cases but it unsets the session (code written in if condition). How is that possible, code to destroy session has been written in if condition. I have tried many things but couldn't reach anywhere. Any suggestion could be a great help. I have tried switch case, in_array and if else.
Try this
$getId = (int) $this->getRequest()->getParam('id');

how do i define an isset($_GET['id']) statement in an $_POST update query

I am carrying 'ID' over from a display table and want to store it in a variable called employee_display_id. I am aware that if you do not create the below function...
if(sset($_GET['id'])){
$employee_display_id = $_GET['iod'];
}
and your proceed to use the '$employee_display_id' variable, you receive an undefined variable error.
How do you incorporate the...
if(sset($_GET['id'])){
$employee_display_id = $_GET['iod'];
}
into...
if(isset($_POST['update']))
{
$updatename = htmlentities(strip_tags(mysql_real_escape_string($_POST['update_name'])));
$updateusername = htmlentities(strip_tags(mysql_real_escape_string($_POST['update_username'])));
echo $update_query = "UPDATE `employees` SET `name`='$updatename', `username`='$updateusername' WHERE `employee_id`='4'";/* $employee_display_id */
$update_result = mysql_query($update_query);
}
else
{
echo mysql_error();
}
so i can use the variable in the WHERE clause of the UPDATE query??
You are checking isset for $_GET['id'] and assigning $_GET['iod']
itz "iod" yu are assigning. Are you sure this variable assigned a value ???
Nazneen has a point. Double-check your variable names.
Also, do you know the difference between GET and POST? How they work?
Presumably, you want to update the employee data from an update link in a table? So your link would be something like http://example.com/update.php?id=6
Well then, in this example, GET['id'] would return 6, which you can then use with your code and pass it into your SQL query.
Example:
if(isset($_POST['update']))
{
if(isset($_GET['id'])){
$employee_display_id = $_GET['id'];
}
if(isset($_POST['update_name'])){
$updatename = htmlentities(strip_tags(mysql_real_escape_string($_POST['update_name'])));
}
// and so on...
}
Does that answer your question?
You could use a shorthand if to determine if the variable is set within the update command, but you need to set it to something or the query will not operate as you expect.
I would recommend checking if the variable is set prior to the SQL. If it's not set don't perform the query.
if(isset($employee_display_id)){
echo $update_query = "UPDATE `employees` SET `name`='$updatename', `username`='$updateusername' WHERE `employee_id`=" . $employee_display_id;
$update_result = mysql_query($update_query);
} else {
echo "ID not set."
}