php - Get data using variable from query string? -
i hope title used here understandable...
i have database 2 columns: ward_id , ward_name.
i wish create dynamic pages each ward , have ward_name show in page title. have created header.php file including.
i passing id through url using ....?wid={$row['ward_id']} working fine when create other queries use id data database.
however problem having page refuses display ward_name page title. expected work:
$wardid = $_get['wid']; $query = "select ward_name, ward_id wards ward_id=$wardid"; $result = mysql_query($query); while ($row=mysql_fetch_array($result)) { $pagetitle = "$row['ward_name']"; }
but doesn't, have tried many variations on above can't possibly remember them hope can me... here code stands:
header page:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title><?php echo $pagetitle; ?></title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="wholepage"> <div class="headlinewrapper"> <div class="headline"> <h1></h1> <h2></h2> </div> </div> <div class="headlinesidewrapper"> <div class="headlineside"> <p>shv jsfj sjnsf jnsf nsnf nj njsfn njfjn sfns njf njnsf njs dgbjn dn jnd njjn dd d d nj njd njnd njd nn djndj njd</p> </div> </div> <div class="topnavigation"> <ul> <li><a href="index.php">home</a></li> <li><a href="boroughs.php">boroughs</a></li> <li><a href="wards.php">wards</a></li> </ul> </div> <div class="sidebar"> </div> <div class="mainpagewrapper">
dynamic page:
<?php $pagetitle = "hello"; include ('header.php'); ?> <div class="mainpage"> <div class="infobox"> </div> <?php require('mysqli_connect.php'); mysql_select_db('onetwom2_london'); $wardid = $_get['wid']; $query = "select ward_name, ward_id wards ward_id=$wardid"; $result = mysql_query($query); while ($row=mysql_fetch_array($result)) { echo "<div class=\"boroughlist\"><p>{$row['ward_name']}</p></div>" ; } $pagetitle = $result; ?> <div class="clear"> </div> </div> </div> </div> </body> </html>
so want know how/if possible match id passed through url ward_id stored on database , have page title display ward_name linked id. apologise if easy question, have spent hours trying work out , stumped! (the code posted above end result of 5 hours of frustration please appreciate have tried hard before asking :) )
you should step through problem see goes awry, var-dump $pagetitle in while loop. see being stored if comes out null not retrieving db , there issue either query. if has correct variable problem php. var_dump $pagetitle in header.php file sure getting correct variable.
let me know outcome , can there
<?php $wardid = $_get['wid']; $query = "select ward_name, ward_id wards ward_id=$wardid"; $result = mysql_query($query); while ($row=mysql_fetch_array($result)) { $pagetitle = "$row['ward_name']"; //step through problem var_dump($pagetitle); } include ('header.php'); ?> <div class="mainpage"> <div class="infobox"> </div> <?php require('mysqli_connect.php'); mysql_select_db('onetwom2_london'); $wardid = $_get['wid']; $query = "select ward_name, ward_id wards ward_id=$wardid"; $result = mysql_query($query); while ($row=mysql_fetch_array($result)) { echo "<div class=\"boroughlist\"><p>{$row['ward_name']}</p></div>" ; } $pagetitle = $result; ?> <div class="clear"> </div> </div>
updated - try
<?php require('mysqli_connect.php'); mysql_select_db('onetwom2_london'); $wardid = $_get['wid']; $query = "select ward_name, ward_id wards ward_id=$wardid"; $result = mysql_query($query); while ($row=mysql_fetch_array($result)) { $pagetitle = $row['ward_name']; //step through problem var_dump($pagetitle); } include ('header.php'); ?> <div class="mainpage"> <div class="infobox"> </div> <?php $result2 = mysql_query($query); while ($row2=mysql_fetch_array($result2)) { echo "<div class=\"boroughlist\"><p>{$row2['ward_name']}</p></div>" ; } ?> <div class="clear"> </div> </div>
Comments
Post a Comment