douhuang5331 2017-07-11 09:56
浏览 29
已采纳

too long

I am very new to php and I am looking to create dynamic pages.

Basically If a person lands on www.example.co.uk/essex.php I would like to be able to add something like <h1>Company In <?php echo $row['County']; ?> so that it would show Company In Essex when Live and save time if I need to duplicate the page for another county or town.

So far I have setup a database in phpmyadmin

Picture of Table

My code so far to grab the table is;

$dbconnect = mysqli_connect("HOST", "USER", "PASSWORD", "DB");
if(mysqli_connect_errno()) {
    echo "Connection Failed:".mysqli_connect_error();
    exit;
}

$count_sql="SELECT * FROM areas";
$count_query=mysqli_query($dbconnect, $count_sql);
$count_rs=mysqli_fetch_assoc($count_query);

and then on www.example.co.uk/essex.php

<?php
do {
    echo $count_rs['County'];
} while ($count_rs=mysqli_fetch_assoc($count_query))

?>

But where I have gone wrong is it pulls all the data from the table for County where I only wish it to pull the county of Essex.

Please forgive me for explaining this badly.

UPDATE -

    $row = url2content();
extract($row);


function url2content($url = NULL){
if(is_null($url)){
if(isset($_SERVER["REQUEST_URI"]) && $_SERVER["REQUEST_URI"]){
$url = $_SERVER["REQUEST_URI"];
}elseif(isset($_SERVER["PATH_INFO"]) && $_SERVER["PATH_INFO"]){
$url = $_SERVER["PATH_INFO"];
}
if (substr($url,0,1) == '/'){
$url = substr($url,1);
}
}
if (DEBUG_MODE){
echo ('URL requested: "'.$url.'"<br>');
}



function get_towns($county){
    $query = sprintf("select townName from " . AREAS_TABLE . " where countyName = '%s'  order by rand() LIMIT 0,24" ,mysql_real_escape_string($county));
    $res = mysql_query($query);
    if(!$res){
        printf("Unable to query ".AREAS_TABLE." table: %s 
", mysql_error());
    }
    $html="";
    while($row = mysql_fetch_assoc($res)){
        $html.="<li>".stripslashes($row["townName"])."</li>
";
    }
    return $html;
}}
  • 写回答

2条回答 默认 最新

  • dongque1462 2017-07-11 10:28
    关注

    You have to use WHERE clause in your query in order to select a specific country from your db
    SELECT * from table WHERE felid_country=$count_rs['County'];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度