作者共發了6篇帖子。 內容轉換:不轉換▼
 
點擊 回復
835 5
PDO(PHP自帶通用數據庫類)鏈接MySQL數據庫
一派護法 十九級
1樓 發表于:2015-5-24 11:26
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PDO</title>
</head>

<body>
<?php
try {
    $db = new PDO("mysql:host=localhost;dbname=test", "用戶名", "密碼");
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}

$sql = "SELECT * FROM WiFiHotSpots";
foreach ($db->query($sql) as $row) {
    echo join(", ", $row);
    echo "<br>";
}
?>
</body>
</html>
一派護法 十九級
2樓 發表于:2015-5-24 11:26
【輸出結果】
1, 1, 7th Brigade Park, Chermside, 7th Brigade Park, Chermside, Delaware St, Delaware St, Chermside, Chermside, , , -27.37893, -27.37893, 153.04461, 153.04461
2, 2, Annerley Library Wifi, Annerley Library Wifi, 450 Ipswich Road, 450 Ipswich Road, Annerley, Annerley, 4103, 4103, -27.5094228, -27.5094228, 153.033321, 153.033321
3, 3, Ashgrove Library Wifi, Ashgrove Library Wifi, 87 Amarina Avenue, 87 Amarina Avenue, Ashgrove, Ashgrove, 4060, 4060, -27.4439462, -27.4439462, 152.987098, 152.987098
4, 4, Banyo Library Wifi, Banyo Library Wifi, 284 St. Vincents Road, 284 St. Vincents Road, Banyo, Banyo, 4014, 4014, -27.3739664, -27.3739664, 153.078323, 153.078323
5, 5, Booker Place Park, Booker Place Park, Birkin Rd & Sugarwood St, Birkin Rd & Sugarwood St, Bellbowrie, Bellbowrie, , , -27.56353, -27.56353, 152.89372, 152.89372
6, 6, Bracken Ridge Library Wifi, Bracken Ridge Library Wifi, Corner Bracken and Barrett Street, Corner Bracken and Barrett Street, Bracken Ridge, Bracken Ridge, 4017, 4017, -27.3179726, -27.3179726, 153.037873, 153.037873
7, 7, Brisbane Botanic Gardens, Brisbane Botanic Gardens, Mt Coot-tha Rd, Mt Coot-tha Rd, Toowong, Toowong, , , -27.47724, -27.47724, 152.97599, 152.97599
8, 8, Brisbane Square Library Wifi, Brisbane Square Library Wifi, Brisbane Square, 266 George Street, Brisbane Square, 266 George Street, Brisbane, Brisbane, 4000, 4000, -27.4709117, -27.4709117, 153.022459, 153.022459
9, 9, Bulimba Library Wifi, Bulimba Library Wifi, Corner Riding Road & Oxford Street, Corner Riding Road & Oxford Street, Bulimba, Bulimba, 4171, 4171, -27.4520308, -27.4520308, 153.062824, 153.062824
10, 10, Calamvale District Park, Calamvale District Park, Formby & Ormskirk Sts, Formby & Ormskirk Sts, Calamvale, Calamvale, , , -27.62152, -27.62152, 153.03665, 153.03665
11, 11, Carina Library Wifi, Carina Library Wifi, Corner Mayfield Road & Nyrang Street, Corner Mayfield Road & Nyrang Street, Carina, Carina, 4152, 4152, -27.4916931, -27.4916931, 153.091212, 153.091212
12, 12, Carindale Library Wifi, Carindale Library Wifi, The Home and Leisure Centre, Corner Carindale Street & Banchory Court, Westfield Carindale Shopping Centre, The Home and Leisure Centre, Corner Carindale Street & Banchory Court, Westfield Carindale Shopping Centre, Carindale, Carindale, 4152, 4152, -27.5047592, -27.5047592, 153.100396, 153.100396
13, 13, Carindale Recreation Reserve, Carindale Recreation Reserve, Cadogan and Bedivere Sts, Cadogan and Bedivere Sts, Carindale, Carindale, , , -27.497, -27.497, 153.11105, 153.11105
14, 14, Chermside Library Wifi, Chermside Library Wifi, 375 Hamilton Road, 375 Hamilton Road, Chermside, Chermside, 4032, 4032, -27.3856032, -27.3856032, 153.034902, 153.034902
15, 15, City Botanic Gardens Wifi, City Botanic Gardens Wifi, Alice Street, Alice Street, Brisbane City, Brisbane City, , , -27.47561, -27.47561, 153.03005, 153.03005
16, 16, Coopers Plains Library Wifi, Coopers Plains Library Wifi, 107 Orange Grove Road, 107 Orange Grove Road, Coopers Plains, Coopers Plains, 4108, 4108, -27.5651050, -27.5651050, 153.040318, 153.040318
17, 17, Corinda Library Wifi, Corinda Library Wifi, 641 Oxley Road, 641 Oxley Road, Corinda, Corinda, 4075, 4075, -27.5388023, -27.5388023, 152.980909, 152.980909
18, 18, D.M. Henderson Park, D.M. Henderson Park, Granadilla St, Granadilla St, MacGregor, MacGregor, , , -27.57745, -27.57745, 153.07603, 153.07603
19, 19, Einbunpin Lagoon, Einbunpin Lagoon, Brighton Rd, Brighton Rd, Sandgate, Sandgate, , , -27.31947, -27.31947, 153.06822, 153.06822
20, 20, Everton Park Library Wifi, Everton Park Library Wifi, 561 South Pine Road, 561 South Pine Road, Everton park, Everton park, 4053, 4053, -27.4053336, -27.4053336, 152.990420, 152.990420
21, 21, Fairfield Library Wifi, Fairfield Library Wifi, Fairfield Gardens Shopping Centre, 180 Fairfield Road, Fairfield Gardens Shopping Centre, 180 Fairfield Road, Fairfield, Fairfield, 4103, 4103, -27.5090903, -27.5090903, 153.025970, 153.025970
22, 22, Forest Lake Parklands, Forest Lake Parklands, Forest Lake Bld, Forest Lake Bld, Forest Lake, Forest Lake, , , -27.62020, -27.62020, 152.96625, 152.96625
23, 23, Garden City Library Wifi, Garden City Library Wifi, Garden City Shopping Centre, Corner Logan and Kessels Road, Garden City Shopping Centre, Corner Logan and Kessels Road, Upper Mount Gravatt, Upper Mount Gravatt, 4122, 4122, -27.5624422, -27.5624422, 153.080918, 153.080918
24, 24, Glindemann Park, Glindemann Park, Logan Rd, Logan Rd, Holland Park West, Holland Park West, , , -27.52552, -27.52552, 153.06923, 153.06923
25, 25, Grange Library Wifi, Grange Library Wifi, 79 Evelyn Street, 79 Evelyn Street, Grange, Grange, 4051, 4051, -27.4253119, -27.4253119, 153.017472, 153.017472
26, 26, Gregory Park, Gregory Park, Baroona Rd, Baroona Rd, Paddington, Paddington, , , -27.467, -27.467, 152.99981, 152.99981
27, 27, Guyatt Park, Guyatt Park, Sir Fred Schonell Dve, Sir Fred Schonell Dve, St Lucia, St Lucia, , , -27.49297, -27.49297, 153.00187, 153.00187
28, 28, Hamilton Library Wifi, Hamilton Library Wifi, Corner Racecourt Road and Rossiter Parade, Corner Racecourt Road and Rossiter Parade, Hamilton, Hamilton, 4007, 4007, -27.4379013, -27.4379013, 153.064222, 153.064222
29, 29, Hidden World Park, Hidden World Park, Roghan Rd, Roghan Rd, Fitzgibbon, Fitzgibbon, , , -27.3397170, -27.3397170, 153.034981, 153.034981
30, 30, Holland Park Library Wifi, Holland Park Library Wifi, 81 Seville Road, 81 Seville Road, Holland Park, Holland Park, 4121, 4121, -27.5229228, -27.5229228, 153.072292, 153.072292
31, 31, Inala Library Wifi, Inala Library Wifi, Inala Shopping centre, Corsair Ave, Inala Shopping centre, Corsair Ave, Inala, Inala, 4077, 4077, -27.5982857, -27.5982857, 152.973521, 152.973521
32, 32, Indooroopilly Library Wifi, Indooroopilly Library Wifi, Indrooroopilly Shopping centre, Level 4, 322 Moggill Road, Indrooroopilly Shopping centre, Level 4, 322 Moggill Road, Indooroopilly, Indooroopilly, 4068, 4068, -27.4976428, -27.4976428, 152.973647, 152.973647
33, 33, Kalinga Park, Kalinga Park, Kalinga St, Kalinga St, Clayfield, Clayfield, , , -27.40666, -27.40666, 153.05217, 153.05217
34, 34, Kenmore Library Wifi, Kenmore Library Wifi, Kenmore Village Shopping Centre, Brookfield Road, Kenmore Village Shopping Centre, Brookfield Road, Kenmore, Kenmore, 4069, 4069, -27.5059285, -27.5059285, 152.938643, 152.938643
35, 35, King Edward Park (Jacob's Ladder), King Edward Park (Jacob's Ladder), Turbot St and Wickham Tce, Turbot St and Wickham Tce, Brisbane, Brisbane, , , -27.46589, -27.46589, 153.02406, 153.02406
36, 36, King George Square, King George Square, Ann & Adelaide Sts, Ann & Adelaide Sts, Brisbane, Brisbane, , , -27.46843, -27.46843, 153.02422, 153.02422
37, 37, Mitchelton Library Wifi, Mitchelton Library Wifi, 37 Helipolis Parada, 37 Helipolis Parada, Mitchelton, Mitchelton, 4053, 4053, -27.4170416, -27.4170416, 152.978340, 152.978340
38, 38, Mt Coot-tha Botanic Gardens Library Wifi, Mt Coot-tha Botanic Gardens Library Wifi, Administration Building, Brisbane Botanic Gardens (Mt Coot-tha), Mt Coot-tha Road, Administration Building, Brisbane Botanic Gardens (Mt Coot-tha), Mt Coot-tha Road, Toowong, Toowong, 4066, 4066, -27.4752990, -27.4752990, 152.976041, 152.976041
39, 39, Mt Gravatt Library Wifi, Mt Gravatt Library Wifi, 8 Creek Road, 8 Creek Road, Mt Gravatt, Mt Gravatt, 4122, 4122, -27.5385548, -27.5385548, 153.080262, 153.080262
40, 40, Mt Ommaney Library Wifi, Mt Ommaney Library Wifi, Mt Ommaney Shopping Centre, 171 Dandenong Road, Mt Ommaney Shopping Centre, 171 Dandenong Road, Mt Ommaney, Mt Ommaney, 4074, 4074, -27.5482419, -27.5482419, 152.937809, 152.937809
41, 41, New Farm Library Wifi, New Farm Library Wifi, 135 Sydney Street, 135 Sydney Street, New Farm, New Farm, 4005, 4005, -27.4673657, -27.4673657, 153.049584, 153.049584
42, 42, New Farm Park Wifi, New Farm Park Wifi, Brunswick Street, Brunswick Street, New Farm, New Farm, , , -27.47046,, -27.47046,, 153.05223, 153.05223
43, 43, Nundah Library Wifi, Nundah Library Wifi, 1 Bage Street, 1 Bage Street, Nundah, Nundah, 4012, 4012, -27.4012590, -27.4012590, 153.058375, 153.058375
44, 44, Oriel Park, Oriel Park, Cnr of Alexandra & Lancaster Rds, Cnr of Alexandra & Lancaster Rds, Ascot, Ascot, , , -27.42928, -27.42928, 153.05768, 153.05768
45, 45, Orleigh Park, Orleigh Park, Hill End Tce, Hill End Tce, West End, West End, , , -27.48995, -27.48995, 153.00326, 153.00326
46, 46, Post Office Square, Post Office Square, Queen & Adelaide Sts, Queen & Adelaide Sts, Brisbane, Brisbane, , , -27.46735, -27.46735, 153.02735, 153.02735
47, 47, Rocks Riverside Park, Rocks Riverside Park, Counihan Rd, Counihan Rd, Seventeen Mile Rocks, Seventeen Mile Rocks, , , -27.54153, -27.54153, 152.95913, 152.95913
48, 48, Sandgate Library Wifi, Sandgate Library Wifi, Seymour Street, Seymour Street, Sandgate, Sandgate, 4017, 4017, -27.3206052, -27.3206052, 153.070492, 153.070492
49, 49, Stones Corner Library Wifi, Stones Corner Library Wifi, 280 Logan Road, 280 Logan Road, Stones Corner, Stones Corner, 4120, 4120, -27.4980357, -27.4980357, 153.043655, 153.043655
50, 50, Sunnybank Hills Library Wifi, Sunnybank Hills Library Wifi, Sunnybank Hills Shopping Centre, Corner Compton and Calam Roads, Sunnybank Hills Shopping Centre, Corner Compton and Calam Roads, Sunnybank Hills, Sunnybank Hills, 4109, 4109, -27.6109253, -27.6109253, 153.055070, 153.055070
51, 51, Teralba Park, Teralba Park, Pullen & Osborne Rds, Pullen & Osborne Rds, Everton Park, Everton Park, , , -27.40286, -27.40286, 152.98059, 152.98059
52, 52, Toowong Library Wifi, Toowong Library Wifi, Toowon Village Shopping Centre, Sherwood Road, Toowon Village Shopping Centre, Sherwood Road, Toowong, Toowong, 4066, 4066, -27.4850511, -27.4850511, 152.992509, 152.992509
53, 53, West End Library Wifi, West End Library Wifi, 178 - 180 Boundary Street, 178 - 180 Boundary Street, West End, West End, 4101, 4101, -27.4824507, -27.4824507, 153.012076, 153.012076
54, 54, Wynnum Library Wifi, Wynnum Library Wifi, Wynnum Civic Centre, 66 Bay Terrace, Wynnum Civic Centre, 66 Bay Terrace, Wynnum, Wynnum, 4178, 4178, -27.4424489, -27.4424489, 153.173196, 153.173196
55, 55, Zillmere Library Wifi, Zillmere Library Wifi, Corner Jennings Street and Zillmere Road, Corner Jennings Street and Zillmere Road, Zillmere, Zillmere, 4034, 4034, -27.3601423, -27.3601423, 153.040789, 153.040789

一派護法 十九級
3樓 發表于:2015-5-24 11:30
一派護法 十九級
4樓 發表于:2015-5-24 12:38
<?php include 'header.inc'; ?>
<?php
$itemID = (int)(@$_GET["id"]);
$sql = "SELECT * FROM Items WHERE ItemID = {$itemID}";
$rs = $db->prepare($sql);
$rs->execute();
$row = $rs->fetch();
?>
    <div id="iteminfo">
        <h2><?=$row["ItemName"]?></h2>
        <b>Here will be the map.</b>
        <br />
        Address: <b><?=$row["ItemAddress"]?></b>
    </div>
    <div id="usercomments">
        <b>Displaying users' comments & rating.</b>
    </div>
    <div id="comment">
        <form name="comment">
            Rating:
            <input type="radio" name="rating" value="1" />1
            <input type="radio" name="rating" value="2" />2
            <input type="radio" name="rating" value="3" />3
            <input type="radio" name="rating" value="4" />4
            <input type="radio" name="rating" value="5" />5 <br />
            Comment: <br />
            <textarea rows="10" cols="30"></textarea><br />
            <input type="submit" value="Submit" />
        </form>
    </div>
<?php include 'footer.inc'; ?>

執行sql語句并查詢
一派護法 十九級
5樓 發表于:2015-5-24 12:39
一派護法 十九級
6樓 發表于:2015-5-24 12:58
Suburb:
           <select name="suburb">
            <?php
            $sql = "SELECT DISTINCT `ItemSuburb` FROM `Items` WHERE `ItemSuburb` != '' ORDER BY `ItemSuburb` ASC";
            $rs = $db->query($sql);
            foreach ($rs as $row){
            ?>
            <option value="<?=$row[0]?>"><?=$row[0]?></option>
            <?php } ?>
        </select><br />

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:835 回複數:5
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2015-5-24 12:58
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。