[PHP+MySQL] - {}呢舊野Ge威力...

編寫、設計網頁與程式。

版主: hamu278, 銘仔

版面規則
  • 本版面亦可以討論網頁寄存公司

[PHP+MySQL] - {}呢舊野Ge威力...

文章SkyBread » 2009-04-05, 00:32

$rss = file_get_contents("http://feed250.photobucket.com/albums/gg268/castlecastle/computer_teach/feed.rss");

$p = explode("<item>", $rss);
$photo_num = count($p)-1;
for($i = 1;$i <= $photo_num;$i++){
$photo_url = explode('<guid>', $rss);
$photo_url[$i] = explode('</guid>', $photo_url[$i]);
$photo_title = explode('<media:title>', $rss);
$photo_title[$i] = explode('</media:title>', $photo_title[$i]);

$db->query("INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '$time_now', '0', '1');");
}

呢3個 { } 搞到我煩足成晚... :oops:
唔加會變哂Array[0]...
SkyBread
 

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章Freeman » 2009-04-05, 00:46

SkyBread 寫:
$rss = file_get_contents("http://feed250.photobucket.com/albums/gg268/castlecastle/computer_teach/feed.rss");

$p = explode("<item>", $rss);
$photo_num = count($p)-1;
for($i = 1;$i <= $photo_num;$i++){
$photo_url = explode('<guid>', $rss);
$photo_url[$i] = explode('</guid>', $photo_url[$i]);
$photo_title = explode('<media:title>', $rss);
$photo_title[$i] = explode('</media:title>', $photo_title[$i]);

$db->query("INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '$time_now', '0', '1');");
}

呢3個 { } 搞到我煩足成晚... :oops:
唔加會變哂Array[0]...

你中左Discuz!毒
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章bananasims » 2009-04-05, 00:57

iamfreeman 寫:
SkyBread 寫:你中左Discuz!毒

phpBB 都係咁寫 :oops:
其實用 double quotation mark 開係好寫過用 single quotation mark 開(相信大家都知 string 用 double 同 single 有乜分別)
如果個 string 有好多 single quotation mark 同埋 variable 的話,double quotation mark 就慢少少,不過啲碼靚;single quotation mark 就快,不過啲碼亂

比個例子,好似 Skybread 啲碼
代碼: 選擇全部
$db->query('INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES (\'\', \'1\', \'1\', \'' . $photo_url[$i][0] . '\', \'' . $photo_title[$i][0] . '\', \'' . $photo_title[$i][0] . '\', \'' . $time_now . '\', \'0\', \'1\');');

啲 backward slash「\」同啲「' . $variable . '」睇到你頭都暈。
所以喺 SQL 層面,我會比較 prefer 用 double quotation mark。
以安全同標準計,不論 array 與否,我都會用大括號包住。
好似咁:
代碼: 選擇全部
$db->query("INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '{$time_now}', '0', '1');");

不過我寫就當然會同 SQL 「包裝」一下
代碼: 選擇全部
$db->query("INSERT INTO `photo` (`pid`, `alid`, `id`, `url`, `title`, `description`, `time`, `hits`, `able`) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '{$time_now}', '0', '1');");

跟標準、好睇之餘,用「`」LEFT JOIN 都好有用 ;)
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章Freeman » 2009-04-05, 01:04

我寧願加多D :oops:
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章bananasims » 2009-04-05, 01:05

改咗回覆 :oops:
加多啲乜? :oops:
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章Freeman » 2009-04-05, 01:09

bananasims 寫:改咗回覆 :oops:
加多啲乜? :oops:

代碼: 選擇全部
' . $variable . '

:oops:
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章bananasims » 2009-04-05, 01:11

不過啲 \' 都幾煩下 :oops:
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章Freeman » 2009-04-05, 01:16

bananasims 寫:不過啲 \' 都幾煩下 :oops:


咁WO...有\咩 :oops:
代碼: 選擇全部
mysql_query('SELECT xxx
                   FROM yyy
                   WHERE zzz <> ' . $val . ');
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章bananasims » 2009-04-05, 01:17

Syntax Error :oops:
我指好似青山咁既 case :oops:
不過我會 prefer 全部 SQL 都用 double quotation mark,改起黎都方便
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章Freeman » 2009-04-05, 01:19

bananasims 寫:Syntax Error :oops:
我指好似青山咁既 case :oops:
不過我會 prefer 全部 SQL 都用 double quotation mark,改起黎都方便

慣左覺得差唔多.... :oops:
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章hamu278 » 2009-04-05, 09:20

你處理緊 XML,點解唔用 DOM / SimpleXML 去處理?狂 explode,超亂 :oops: :oops:
圖檔
頭像
hamu278
金星會員
 
文章: 4482
註冊時間: 2006-06-04, 08:49
來自: 香港

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章bananasims » 2009-04-05, 09:22

不如寫個 class 用 jQuery 既 selector 方式選取 XML 元素 :oops:
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章hamu278 » 2009-04-05, 09:30

已有現成 class
phpQuery - http://code.google.com/p/phpquery/
圖檔
頭像
hamu278
金星會員
 
文章: 4482
註冊時間: 2006-06-04, 08:49
來自: 香港

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章jl9404 » 2009-04-05, 21:31

加多幾粒字洗死咩 :ugeek:
jl9404
土星會員
 
文章: 153
註冊時間: 2007-01-09, 19:50

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章SkyBread » 2009-04-05, 23:19

bananasims 寫:
iamfreeman 寫:
SkyBread 寫:你中左Discuz!毒

phpBB 都係咁寫 :oops:
其實用 double quotation mark 開係好寫過用 single quotation mark 開(相信大家都知 string 用 double 同 single 有乜分別)
如果個 string 有好多 single quotation mark 同埋 variable 的話,double quotation mark 就慢少少,不過啲碼靚;single quotation mark 就快,不過啲碼亂

比個例子,好似 Skybread 啲碼
代碼: 選擇全部
$db->query('INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES (\'\', \'1\', \'1\', \'' . $photo_url[$i][0] . '\', \'' . $photo_title[$i][0] . '\', \'' . $photo_title[$i][0] . '\', \'' . $time_now . '\', \'0\', \'1\');');

啲 backward slash「\」同啲「' . $variable . '」睇到你頭都暈。
所以喺 SQL 層面,我會比較 prefer 用 double quotation mark。
以安全同標準計,不論 array 與否,我都會用大括號包住。
好似咁:
代碼: 選擇全部
$db->query("INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '{$time_now}', '0', '1');");

不過我寫就當然會同 SQL 「包裝」一下
代碼: 選擇全部
$db->query("INSERT INTO `photo` (`pid`, `alid`, `id`, `url`, `title`, `description`, `time`, `hits`, `able`) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '{$time_now}', '0', '1');");

跟標準、好睇之餘,用「`」LEFT JOIN 都好有用 ;)

insert有得left join咩... :shock: :?:
SkyBread
 

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章SkyBread » 2009-04-05, 23:22

iamfreeman 寫:
SkyBread 寫:
$rss = file_get_contents("http://feed250.photobucket.com/albums/gg268/castlecastle/computer_teach/feed.rss");

$p = explode("<item>", $rss);
$photo_num = count($p)-1;
for($i = 1;$i <= $photo_num;$i++){
$photo_url = explode('<guid>', $rss);
$photo_url[$i] = explode('</guid>', $photo_url[$i]);
$photo_title = explode('<media:title>', $rss);
$photo_title[$i] = explode('</media:title>', $photo_title[$i]);

$db->query("INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '$time_now', '0', '1');");
}

呢3個 { } 搞到我煩足成晚... :oops:
唔加會變哂Array[0]...

你中左Discuz!毒

你指mysql個class定係explode?? :oops:
SkyBread
 

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章bananasims » 2009-04-05, 23:26

SkyBread 寫:insert有得left join咩... :shock: :?:

我指全部 SQL :oops:
影像.從心 At the heart of the ímage
bananasims
太陽會員
 
文章: 13541
註冊時間: 2005-09-22, 00:00

Re: [PHP+MySQL] - {}呢舊野Ge威力...

文章Freeman » 2009-04-06, 00:36

SkyBread 寫:
iamfreeman 寫:
SkyBread 寫:
$rss = file_get_contents("http://feed250.photobucket.com/albums/gg268/castlecastle/computer_teach/feed.rss");

$p = explode("<item>", $rss);
$photo_num = count($p)-1;
for($i = 1;$i <= $photo_num;$i++){
$photo_url = explode('<guid>', $rss);
$photo_url[$i] = explode('</guid>', $photo_url[$i]);
$photo_title = explode('<media:title>', $rss);
$photo_title[$i] = explode('</media:title>', $photo_title[$i]);

$db->query("INSERT INTO photo (pid, alid, id, url, title, description, time, hits, able) VALUES ('', '1', '1', '{$photo_url[$i][0]}', '{$photo_title[$i][0]}', '{$photo_title[$i][0]}', '$time_now', '0', '1');");
}

呢3個 { } 搞到我煩足成晚... :oops:
唔加會變哂Array[0]...

你中左Discuz!毒

你指mysql個class定係explode?? :oops:

coding standard :oops:
Freeman
地球會員
 
文章: 1680
註冊時間: 2008-06-25, 21:04


回到 [B1] 網頁製作、程式編寫與介面設計



誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 12 位訪客

cron