小编Mer*_*na 的帖子

mysql_select_db()期望参数2是资源,给定对象

我是使用PHP的新手.我做了一些简单的连接到MySQL并选择了一个数据库:

$conn = mysqli_connect($db_host, $db_admin, $db_pass) or die(mysql_error());
// these variables are previously declared and initialized 

$selected_db = mysql_select_db($db_name, $conn) or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)

当我测试它时,我得到了一个成功建立的连接和以下警告:

mysql_select_db() expects parameter 2 to be resource, object given 
Run Code Online (Sandbox Code Playgroud)

为什么会这样?我该如何解决?

php mysql

7
推荐指数
1
解决办法
5万
查看次数

需要算法来找到第n个回文数

考虑一下

    0 -- is the first
    1 -- is the second
    2 -- is the third
    .....
    9 -- is the 10th
    11 -- is the 11th
Run Code Online (Sandbox Code Playgroud)

什么是找到第n个回文数的有效算法?

c++ algorithm palindrome

3
推荐指数
1
解决办法
2080
查看次数

beautifulsoup - 在div中提取链接

我有一个像以下内容的汤

很多div,我感兴趣的人都有"foo"类

在每个div中,有很多链接和其他内容,我对第二个链接感兴趣(第二个<a> </a>)=>它总是第二个我想要获取链接(在href属性中)和第二个链接标记之间的文本<a> </a>

例如 :

<div class ="foo">
     <a href ="http://example.com"> </a>
     <a href ="http://example2.com"> Title here </a>
</div>

<div class ="foo">
     <a href ="http://example3.com"> </a>
     <a href ="http://example4.com"> Title 2 here </a>
</div>
Run Code Online (Sandbox Code Playgroud)

在这里,我想得到:

这里标题=> http://example2.com

标题2在这里=> http://example4.com

我试过写一些代码:

soup.findAll("div", { "class" : "foo" })
Run Code Online (Sandbox Code Playgroud)

但是这会返回一个包含所有div及其内容的列表,我不知道如何更进一步

谢谢 :)

python screen-scraping beautifulsoup

2
推荐指数
1
解决办法
5901
查看次数

在C中,什么是"%n"?这段代码是如何工作的?

在c编程语言中,什么是占位符"%n"?以及下面的代码如何工作?

    char s[150];
    gets(s);
    int read, cur = 0,x;
    while(sscanf(s+cur, "%d%n", &x, &read) == 1)
    {
        cur+= read;
        /// do sth with x
    }
Run Code Online (Sandbox Code Playgroud)

- 此代码获取一行作为字符数组,然后扫描此字符数组中的数字,例如:如果 下次*s="12 34 567" 第一次 最后一次x = 12x = 34x = 567

c format scanf

0
推荐指数
1
解决办法
884
查看次数

标签 统计

algorithm ×1

beautifulsoup ×1

c ×1

c++ ×1

format ×1

mysql ×1

palindrome ×1

php ×1

python ×1

scanf ×1

screen-scraping ×1