很抱歉,如果这个发布了很多,但搜索字段喜欢重新调整"=",所以很难搜索== javascript"== javascript"等.
但我有一些我正在编写的代码,在某些地方==是必需的,而在其他地方=是必需的.有人可以解释这些差异或指出我可以在资源方向上做些什么?
例:
if ($('#block').css.display=='none') {
$('#block').css.display='block';
Run Code Online (Sandbox Code Playgroud)
我能想到的唯一一件事是,我正在改变,而另一方面我正在检查.但在这两者中我指的是平等.
可能重复:
3个不同的等于
任何人都可以告诉我为什么,当使用下面的代码时,我被重定向到elephant.com而不是看到'长颈鹿!
<?php
$foo="giraffe";
if($foo="elephant"){
header("location:http://www.elephant.com");
exit();
}else{
echo $foo;}
?>
Run Code Online (Sandbox Code Playgroud)
谢谢你的期待
Ĵ
我有一个if else语句,但它无法正常工作.当我添加它时,它只回显第一个语句,即使数据库信息=
与if语句中的不匹配,我做错了什么?
$gameum = $db->fetch("SELECT * FROM accounts WHERE `id` = '$id'");
$status = $gameum['status'];
$gameid = $gameum['gameid'];
$search = $gameum['seraching_for'];
if($gameum['status'] = '0' ) {
$data ='<h1> Who do you want to battle against? </h1><br />
<form action="" method="post" id="form-pb" name="pb" target="_self" >
USERNAME:<input name="name" type="text" size="40" maxlength="40" />
<input name="submit" type="submit" value="Search"/>
</form>
<a class="goback" href="#">Cancel</a>';
} else {
$data = '<h1> Searching </h1> <br /> Searching for '.$search.'';
}
Run Code Online (Sandbox Code Playgroud)
数据库行的屏幕截图:
我尝试做的是:
我尝试将布尔值传递给我的视图以检查其是否正确。如果将其设置为true,我想添加一个类。我用Laravel。实际上,这是我的情况:
这是我的代码:
index.blade.php
@foreach($finances as $finance)
@if ($finance->depense = 1)
<tr class="red">
@elseif ($finance->depense = 0)
<tr>
@endif
<td><a href="{{ URL::to('finances/' . $finance->id) }}">{{$finance->description}}</a></td>
<td>{{ $finance->depense }}</td>
<td>{{ $finance->prix }}</td>
<td>{{ $finance->tps }}</td>
<td>{{ $finance->tvq }}</td>
<td>{{ $finance->grandtotal }}</td>
</tr>
@endforeach
Run Code Online (Sandbox Code Playgroud)
FinancesController.php
public function index()
{
$finances = Finance::all();
return View::make('finances.index')->withFinances($finances);
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
代码输出"我将前往洛杉矶.行程将是300英里的距离.我们将需要停止2次." 什么时候它应该根据我的IF语句中定义的数字拉出"停止"这个单词的复数或单数(在这种情况下,它应该是复数).由于我构建类的方式,我猜测IF不能像我预期的那样工作.任何帮助修复它将不胜感激.
class trip {
public $destination;
public $distance;
public $unit;
public $stops = null;
public $transport = null;
function __construct($destination, $distance, $unit, $stops, $transport) {
$this->destination = $destination;
$this->distance = $distance;
$this->unit = $unit;
$this->stops = $stops;
$this->transport = $transport;
}
function getTrip() {
$a = "I will be going to " . $this->destination . ". ";
$a .= "The journey will be a distance of " . $this->distance . " " . $this->unit . ". ";
$a .= …
Run Code Online (Sandbox Code Playgroud) 我是PHP的新手,所以如果这个功能做得不好,请原谅我.
我有一个功能:
function socialLink($sm_type = NULL) {
if ($sm_type = 'twitter') {
echo 'https://www.twitter.com';
} else {
echo 'https://www.facebook.com';
}
}
Run Code Online (Sandbox Code Playgroud)
在我调用函数的代码中,socialLink('facebook');
它回显了Twitter的URL.
当然,它应该呼应Facebook的网址,因为$sm_type
就等于'facebook'
没有twitter
?
任何帮助,将不胜感激.
由于某种原因,此代码不会在我的编译器中运行.意图(作为更大项目的一部分)是对特定主机执行3次ping操作,或直到成功为止,以先到者为准.它没有产生任何错误,只是终止.如果我从while语句中删除第二个条件,它的工作正常,但是我需要更复杂的东西才能在成功的ping上终止循环.我有一段时间没有碰过PHP,所以我可能会错过一些愚蠢的东西.
<?php
function pingAddress($ip) {
//Set variable to limit loops and end if live
$pass = 0;
$result = 0;
//Create conditions for while loop
while( ( $pass < 3 ) && ( $result = 0 ) ) {
//Count loops
$pass++;
//Execute ping
$output=shell_exec('ping -n 1 '.$ip);
//Display ping results for testing purposes
echo "<pre>$output</pre>";
//Check for "TTL" presence
if(strpos($output, 'TTL') !== false)
{
//Notate positive result
$result++;
//Display for testing
echo "Alive";
}
//Display negative result for testing …
Run Code Online (Sandbox Code Playgroud) 我试图了解这里发生了什么:
data.toPage = $('div#someID');
if ( typeof data.toPage === "string" ) {
// sth
console.log("hello");
}
Run Code Online (Sandbox Code Playgroud)
所以我正在检查字符串,不是吗?我好奇,因为我的控制台"helloes".
谢谢你的一些意见!
<?php
if ($user->getProfile()->get('title')="Canon"); {
echo "Test1"; }
else {
echo "Test2"; }
?>
Run Code Online (Sandbox Code Playgroud)
这导致我的网站破裂,是否有明显的错误?谢谢.
这是我的第一篇文章。
我试图检查我的 MySQL 数据库,看看该用户是管理员还是普通用户,它总是说我是管理员。我的数据库是:
ID 姓名 电子邮件 密码 角色
我有一个测试用户: id:1 名称:admin 电子邮件:admin@admin.com 角色:2
我的代码是:
<?php if (isset($_SESSION['usr_id']) || $row["role"] = 1) { ?>
<!DOCTYPE html>
<html>
<head>
<h2>You are a admin!</h2>
</head>
</html>
<?php } else { ?>
<h2>You are either not logged in, or you have no access to this page.</h2>
<?php } ?>
Run Code Online (Sandbox Code Playgroud)
然而,即使我的角色是 2,它总是说我是管理员!
我正在尝试这个,但似乎并不适合我.我从这里参考了.以下是我的代码:
$today = date('Y-m-d');
$date = new DateTime();
$R1D2 = $date->setISODate($year,$week,1)->format('Y-m-d');
<td width="14.285%" <?php if ($R1D2 = $today): ?> style="background:#EEEEEE" <?php endif ?>>some content here </td>
Run Code Online (Sandbox Code Playgroud)
结果是,即使它不相等,所有单元格也会改变其背景 $today