我的服务提供商重置了我的php.ini文件。我的PHP代码没有改变,但现在我的所有功能都没有工作?
我正在运行php.ini 5.2我需要打开或关闭什么才能让以下代码再次运行?
提前感谢您的帮助
function characterListPost() {
global $wpdbNew;
$q = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$rows = $wpdbNew->get_results($q,ARRAY_A);
// start with nonsense value to force a heading
$previous_season = 0;
$outputTwo='';
$i = 1;
foreach ($rows as $row) {
$outputTwo.= "<div class=\"characterbox\" id=\"div{$i}\">";
$i++;
$outputTwo.= "<div class=\"ch_name\">{$row["ch_name"]}</div>";
$outputTwo.= "<div><image class=\"ch_image\" id=\"ch_image{$row["id"]}\" alt=\"character image TBA\" src=\"{$row["ch_image"]}\" /></div>";
$outputTwo.= "<div class=\"ch_description\"><p>{$row["ch_description"]}</p></div>";
$outputTwo.= "<div class=\"ch_age\"><b>Age:</b> {$row["ch_age"]}</div>";
$outputTwo.= "<div class=\"ch_like\"><b>Like:</b> {$row["ch_like"]}</div>";
$outputTwo.= "<div class=\"ch_dislike\"><b>Dislike:</b> {$row["ch_dislike"]}</div>";
$outputTwo.= "<div class=\"Down10px clear\"></div>";
$outputTwo.= "</div>";
}
// echo test successful but $outputTwo will not display?
echo 'Connected successfully';
return $outputTwo;
}
?>
我测试了db代码,它的工作原理是通过消除过程,问题必须在我的php.ini文件和上面的函数代码之间
<?php
$wpdbNew = new wpdb('myacc.myhost.com', 'myusername', 'mypassword', 'mydbname');
if (!$wpdbNew) {
die('Could not connect: ' . mysql_error());
}
以下内容已经在php.ini
中allow_url_fopen = On
allow_url_include = On
register_long_arrays = On
register_globals = On
第二部分,根据下面提供的答案,获取以下代码
EDIT 通过删除foreach ($rows as $row) {
让它发挥作用
一切都准备就绪了!
<?php
episodeListPost();
function episodeListPost() {
$host = 'mydomain.com';
$user = 'myusername';
$pass = 'mypassword';
$data = 'dbname';
$cn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($data, $cn) or die(mysql_error());
$sql = "SELECT id, season_num, temp_eps_num, eps_num, title, inspired, descrip FROM season ORDER BY season_num, temp_eps_num";
$result = mysql_query($sql, $cn) or die(mysql_error());
if($result) {
$previous_season = 0;
$outputOne='';
$i = 1;
while($row = mysql_fetch_assoc($result)) {
foreach ($rows as $row) {
$season = $row["season_num"];
if ($season != $previous_season){
$outputOne.= "<div class=\"seasonTitle\">Season $season</div>";
$previous_season = $season;
}
$outputOne.= "<div class=\"clear\">Episode: {$row["eps_num"]}</div>";
$outputOne.= "<div class=\"epsTitle\">Title: <span class=\"epsTitleOutput\">{$row["title"]}</span></div><div class=\"epsInsp\"> {$row["inspired"]}</div>";
$outputOne.= "<div class=\"epsDiscrip\">{$row["descrip"]}</div>";
$outputOne.= "<div class=\"Down10px\"></div>";
}
if($i == 1) { }
echo $outputOne;
mysql_free_result($result);
} else {
echo 'No results';
}
mysql_close($cn);
}
?>
答案 0 :(得分:1)
以下功能。最有可能的是,您的查询未返回任何结果,或者函数$ wpdbNew-&gt; get_results()未返回任何记录。
function characterListPost() {
global $wpdbNew;
$q = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$rows = $wpdbNew->get_results($q,ARRAY_A);
// start with nonsense value to force a heading
$previous_season = 0;
$outputTwo='';
$i = 1;
foreach ($rows as $row) {
$outputTwo.= "<div class=\"characterbox\" id=\"div{$i}\">";
$i++;
$outputTwo.= "<div class=\"ch_name\">{$row["ch_name"]}</div>";
$outputTwo.= "<div><image class=\"ch_image\" id=\"ch_image{$row["id"]}\" alt=\"character image TBA\" src=\"{$row["ch_image"]}\" /></div>";
$outputTwo.= "<div class=\"ch_description\"><p>{$row["ch_description"]}</p></div>";
$outputTwo.= "<div class=\"ch_age\"><b>Age:</b> {$row["ch_age"]}</div>";
$outputTwo.= "<div class=\"ch_like\"><b>Like:</b> {$row["ch_like"]}</div>";
$outputTwo.= "<div class=\"ch_dislike\"><b>Dislike:</b> {$row["ch_dislike"]}</div>";
$outputTwo.= "<div class=\"Down10px clear\"></div>";
$outputTwo.= "</div>";
}
// echo test successful but $outputTwo will not display?
echo 'Connected successfully.';
if($i == 1) { echo '<br />' . 'No Rows Found'; } else { echo '<br />' . $i . ' Rows Found'; }
return $outputTwo;
}
<?php
characterListPost();
function characterListPost() {
$host = '127.0.0.1';
$user = 'root';
$pass = '';
$data = 'test';
$cn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($data, $cn) or die(mysql_error());
$sql = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$result = mysql_query($sql, $cn) or die(mysql_error());
if($result) {
$previous_season = 0;
$outputTwo='';
$i = 1;
while($row = mysql_fetch_assoc($result)) {
$outputTwo.= "\n\n" . '<!--- ROW #' . $i . ' -->' . "\n";
$outputTwo.= '<div class="characterbox" id="div' . $i . '">' . "\n";
$i++;
$outputTwo.= '<div class="ch_name">' . $row["ch_name"] . '</div>' . "\n";
$outputTwo.= '<div><image class="ch_image" id="ch_image' . $row["id"] . '" alt="character image TBA" src="' . $row["ch_image"] . '" /></div>' . "\n";
$outputTwo.= '<div class="ch_description"><p>' . $row["ch_description"] . '</p></div>' . "\n";
$outputTwo.= '<div class="ch_age"><b>Age:</b> ' . $row["ch_age"] . '</div>' . "\n";
$outputTwo.= '<div class="ch_like"><b>Like:</b> ' .$row["ch_like"] . '</div>' . "\n";
$outputTwo.= '<div class="ch_dislike"><b>Dislike:</b> ' . $row["ch_dislike"] . '</div>' . "\n";
$outputTwo.= '<div class="Down10px clear"></div>' . "\n";
$outputTwo.= '</div>' . "\n";
}
if($i == 1) { echo '<br />' . 'No Rows Found'; } else { echo '<br />' . $i . ' Rows Found'; }
echo '<textarea>' . $outputTwo . '</textarea>';
mysql_free_result($result);
} else {
echo 'No results';
}
mysql_close($cn);
}
?>
用这个替换功能应该有效。别忘了打电话给'characterListPost()&#39;无论在哪里输出。
function characterListPost() {
$host = '127.0.0.1';
$user = 'root';
$pass = '';
$data = 'test';
$cn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($data, $cn) or die(mysql_error());
$sql = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$result = mysql_query($sql, $cn) or die(mysql_error());
$return = "";
if($result) {
$previous_season = 0;
$outputTwo='';
$i = 1;
while($row = mysql_fetch_assoc($result)) {
$outputTwo.= "<div class=\"characterbox\" id=\"div{$i}\">";
$i++;
$outputTwo.= "<div class=\"ch_name\">{$row["ch_name"]}</div>";
$outputTwo.= "<div><image class=\"ch_image\" id=\"ch_image{$row["id"]}\" alt=\"character image TBA\" src=\"{$row["ch_image"]}\" /></div>";
$outputTwo.= "<div class=\"ch_description\"><p>{$row["ch_description"]}</p></div>";
$outputTwo.= "<div class=\"ch_age\"><b>Age:</b> {$row["ch_age"]}</div>";
$outputTwo.= "<div class=\"ch_like\"><b>Like:</b> {$row["ch_like"]}</div>";
$outputTwo.= "<div class=\"ch_dislike\"><b>Dislike:</b> {$row["ch_dislike"]}</div>";
$outputTwo.= "<div class=\"Down10px clear\"></div>";
$outputTwo.= "</div>";
}
// if($i == 1) { echo '<br />' . 'No Rows Found'; } else { echo '<br />' . $i . ' Rows Found'; }
$return = $outputTwo;
mysql_free_result($result);
// } else {
// echo 'No results';
}
mysql_close($cn);
return $return;
}