当前位置:Gxlcms > PHP教程 > javascript-PHP和Ajax做的分页跳转,可是出不来。望大神能看看

javascript-PHP和Ajax做的分页跳转,可是出不来。望大神能看看

时间:2021-07-01 10:21:17 帮助过:3人阅读

想做一个ajax局部刷新分页跳转,可是不知道为什么用ajax接受的数据在页面
上显示出来总是这么一句话MySql ErrorNo database selected 然后我做了几个测试
发现echo"111111";echo"22222";echo"3333"echo"4444";只有4444输出!PHP我不是很懂
所以想麻烦大神们看下是怎么回事!小弟在此谢过了!



" . $row['id'] . " " . $htmlmsg . "";
    }
    $msg = "
    " . $msg . "
"; // Content for Data **echo "3333333333333333333333";** /* --------------------------------------------- */ $query_pag_num = "SELECT COUNT(*) AS count FROM content"; $result_pag_num = mysql_query($query_pag_num); $row = mysql_fetch_array($result_pag_num); $count = $row['count']; $no_of_paginations = ceil($count / $per_page); **echo "2222222222";** /* ---------------Calculating the starting and endign values for the loop----------------------------------- */ if ($cur_page >= 7) { $start_loop = $cur_page - 3; if ($no_of_paginations > $cur_page + 3) $end_loop = $cur_page + 3; else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) { $start_loop = $no_of_paginations - 6; $end_loop = $no_of_paginations; } else { $end_loop = $no_of_paginations; } } else { $start_loop = 1; if ($no_of_paginations > 7) $end_loop = 7; else $end_loop = $no_of_paginations; } /* ----------------------------------------------------------------------------------------------------------- */ $msg .= "
    "; // FOR ENABLING THE FIRST BUTTON if ($first_btn && $cur_page > 1) { $msg .= "
  • First
  • "; } else if ($first_btn) { $msg .= "
  • First
  • "; } // FOR ENABLING THE PREVIOUS BUTTON if ($previous_btn && $cur_page > 1) { $pre = $cur_page - 1; $msg .= "
  • Previous
  • "; } else if ($previous_btn) { $msg .= "
  • Previous
  • "; } for ($i = $start_loop; $i <= $end_loop; $i++) { if ($cur_page == $i) $msg .= "
  • {$i}
  • "; else $msg .= "
  • {$i}
  • "; } // TO ENABLE THE NEXT BUTTON if ($next_btn && $cur_page < $no_of_paginations) { $nex = $cur_page + 1; $msg .= "
  • Next
  • "; } else if ($next_btn) { $msg .= "
  • Next
  • "; } // TO ENABLE THE END BUTTON if ($last_btn && $cur_page < $no_of_paginations) { $msg .= "
  • Last
  • "; } else if ($last_btn) { $msg .= "
  • Last
  • "; } $goto = ""; $total_string = "Page " . $cur_page . " of $no_of_paginations"; $msg = $msg . "
" . $goto . $total_string . ""; // Content for pagination **echo $msg;** **echo "1111111111111";** } ?>

以上是代码

回复内容:

想做一个ajax局部刷新分页跳转,可是不知道为什么用ajax接受的数据在页面
上显示出来总是这么一句话MySql ErrorNo database selected 然后我做了几个测试
发现echo"111111";echo"22222";echo"3333"echo"4444";只有4444输出!PHP我不是很懂
所以想麻烦大神们看下是怎么回事!小弟在此谢过了!



" . $row['id'] . " " . $htmlmsg . "";
    }
    $msg = "
    " . $msg . "
"; // Content for Data **echo "3333333333333333333333";** /* --------------------------------------------- */ $query_pag_num = "SELECT COUNT(*) AS count FROM content"; $result_pag_num = mysql_query($query_pag_num); $row = mysql_fetch_array($result_pag_num); $count = $row['count']; $no_of_paginations = ceil($count / $per_page); **echo "2222222222";** /* ---------------Calculating the starting and endign values for the loop----------------------------------- */ if ($cur_page >= 7) { $start_loop = $cur_page - 3; if ($no_of_paginations > $cur_page + 3) $end_loop = $cur_page + 3; else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) { $start_loop = $no_of_paginations - 6; $end_loop = $no_of_paginations; } else { $end_loop = $no_of_paginations; } } else { $start_loop = 1; if ($no_of_paginations > 7) $end_loop = 7; else $end_loop = $no_of_paginations; } /* ----------------------------------------------------------------------------------------------------------- */ $msg .= "
    "; // FOR ENABLING THE FIRST BUTTON if ($first_btn && $cur_page > 1) { $msg .= "
  • First
  • "; } else if ($first_btn) { $msg .= "
  • First
  • "; } // FOR ENABLING THE PREVIOUS BUTTON if ($previous_btn && $cur_page > 1) { $pre = $cur_page - 1; $msg .= "
  • Previous
  • "; } else if ($previous_btn) { $msg .= "
  • Previous
  • "; } for ($i = $start_loop; $i <= $end_loop; $i++) { if ($cur_page == $i) $msg .= "
  • {$i}
  • "; else $msg .= "
  • {$i}
  • "; } // TO ENABLE THE NEXT BUTTON if ($next_btn && $cur_page < $no_of_paginations) { $nex = $cur_page + 1; $msg .= "
  • Next
  • "; } else if ($next_btn) { $msg .= "
  • Next
  • "; } // TO ENABLE THE END BUTTON if ($last_btn && $cur_page < $no_of_paginations) { $msg .= "
  • Last
  • "; } else if ($last_btn) { $msg .= "
  • Last
  • "; } $goto = ""; $total_string = "Page " . $cur_page . " of $no_of_paginations"; $msg = $msg . "
" . $goto . $total_string . ""; // Content for pagination **echo $msg;** **echo "1111111111111";** } ?>

以上是代码

看一下文档啊 少年 点击链接
既然你是用的mysqli,三楼说的没错,选择一下数据库,mysqli是mysqli_select_db()这个,链接里有,你看下。

mysql 和mysqli混用!
上面用的$conn=mysqli_connect("localhost","root","","info");
下面用mysql_query($query_pag_data)

要不改成

$conn=mysql_connect("localhost","root","","info");
mysql_query($conn,"SET NAMES 'utf8'");

这个报错是因为没有选择数据库呀,你在连接之后执行一下mysqli_query('use database')database是你的数据库,另外像楼上说的,别mysqli和mysql混杂用,php官方已经放弃mysql扩展了,用pdo或者mysqli

人气教程排行