Jump to content

Creating Unique URLS from DB ID


Dada78

Recommended Posts

I am not sure how to explain this but here it goes. I have a page that is displaying information from a database as you can see on this page. All the information that is being outputted in the HTML is coming from the database.

 

http://mesquitechristmas.com/local/displays.php

 

Now notice the URL it is displays.php. I need to be able to use this same template but but change the output of data for each entry in the database. For example taking the URL from above and making it

 

http://mesquitechristmas.com/local/displays.php?id=2 for that display

 

Then to show another display using the same template and url it would change to

 

http://mesquitechristmas.com/local/displays.php?id=3 while all using the same template only the data that is being shown it is is changing.

 

Noticing the only thing that changes is the id number which is calling a certain row in the data base. Now each row in the database has a column called ID and it is auto increment. Now I know how to call a page within a php page but how do you do it so that you can use the same template but change what is outputted just from changing the URL ID from the database. I hope that makes sense.

 

If you need another example look at this site.

 

http://www.christmaslightfinder.com/displays.php?id=322

 

Then change the number at the end to like 323 or 324 etc. You will know the page stays the same only the data changes on the page changes. So I need to know how to do that by using the same template but changing the data by the id of the database and displaying it in the URL.

 

 

-Thanks

 

Link to comment
Share on other sites

Thanks have tried that and I get this error

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mesquit1/public_html/local/displays.php on line 10

 

Here is the page

 

http://mesquitechristmas.com/local/displays.php

 

Here is the entire code for that page.

 

<?php

include ('db_connect.php');

if (isset($_GET['id'])) {
    $id = mysql_real_escape_string($_GET['id']);
    $sql = "SELECT * FROM users WHERE id = $id;";
  }

$row = mysql_fetch_array($result);
$displayname = $row["displayname"];
$displaytype = $row["displaytype"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"]; 
$postal = $row["postal"];
$country = $row["country"];
$rating = $row['rating'];
$votes = $row['votes'];

{

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Mesquite Texas Country Christmas" />
<meta name="keywords" content="Mesquite, Texas, Country Christmas" />
<meta name="author" content="NA" />
<link rel="stylesheet" type="text/css" href="/stylesheet.css" media="screen" title="FBC" />
<script type="text/javascript" src="drop_down.js"></script>
<title>A Mesquite Country Christmas</title>
</head>
<body>

<div id="wrap">

<a href="/index.html">
<img id="frontphoto" src="/images/header.png" width="760" height="237" alt="Mesquite Country Christmas" border="0"></a>

<div id="menu">

<h2 class="hide">Menu:</h2>

<ul id="avmenu">
<li><a href="/index.html">Home</a></li>
<li><a href="/christmasstory.html">The Christmas Story</a></li>
<li><a href="/directions.html">Directions</a></li>
<li><a href="#">Information</a><ul>
      <li><a href="/information.html">Display Facts & Info</a></li>
      <li><a href="/faq.html">FAQ</a></li>
      <li><a href="/playlist.html">2008 Playlist</a></li>
      <li><a href="#">Christmas History</a></li>
  </ul></li>
<li><a href="#">Photos</a>
  <ul>
      <li><a href="/2007photos.html">2007</a></li>
  </ul></li>
<li><a href="#">Videos</a>
  <ul>
      <li><a href="/2007videos.html">2007</a></li>
  </ul></li>
<li><a href="/guestbook.php">Guestbook</a></li>
<li><a href="/webcam.html">Web Cam</a></li>
<li><a href="/webradio.html">Internet Radio</a></li>
<li><a href="http://www.noradsanta.org/" TARGET="_blank">Track Santa</a></li>
<li><a href="/projects.html">Projects & How Tos</a></li>
<li><a href="/links.html">Links</a></li>
<li><a href="/contact_us.html">Contact Us</a></li>
</ul>

<center><a href="http://www.toysfortots.org/" TARGET="_blank"><img src="/images/toys_for_tots.jpg" border="0" width="110" height="153" vspace="10"></a></center>

<center><a href="http://christmas.bronners.com/2007/house/534.html"><img src="http://christmas.bronners.com/voteforme/vote.jpg" border="0" width="110" height="153" alt="christmas decorations" vspace="10"></a></center>

</div>

<div id="content">


<div class="fadebox">

<h2><? echo $row['displayname']; ?></h2>

<hr />

<br>

<table border="0" cellpadding="4" cellspacing="0" width="100%">

<tbody>
     <tr>
        <td align="center"><img src="http://www.christmaslightfinder.com/images/submitted/11283740-large.jpg" class="border"></td>

<p></p></td></tr><tr><td><center>Rated 0 from 0 people | <b>Rate This</b>: <a href="displays.php?id=397&rate=1">1</a> | <a href="displays.php?id=397&rate=2">2</a> | <a href="displays.php?id=397&rate=3">3</a> | <a href="displays.php?id=397&rate=4">4</a> | <a href="displays.php?id=397&rate=5">5</a>
</td><td> </td></tr></tbody></table>

<table align="center" style="border-top: 1px solid rgb(51, 102, 51);" border="0" cellpadding="4" cellspacing="0" width="100%">

<p><a name="info"><span class="title">About this Display...</span>
<tbody><tr><td class="bg2" width="100"><b>Display Name</b>:</td><td class="bg2"><? echo $row['displayname']; ?></td></tr><tr><td class="bg1"><b>Display Type</b>:</td><td class="bg1"><? echo $row['displaytype']; ?></td></tr><tr><td class="bg2"><b>Description</b>:</td><td class="bg2"><? echo $row['description']; ?></td></tr><tr><td class="bg1"><b>Address</b>:</td><td class="bg1"><? echo $row['address']; ?><br><? echo $row['city']. "," . $row['state']. " " . $row['postal']; ?><br><? echo $row['country']; ?><br><a href="http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=<? echo $row['address']; ?>&city=<? echo $row['city']; ?>&zipcode=<? echo $row['postal']; ?>&historyid=&submit=Get+Map" target="_NEW"><b>Get Directions</b></a></td></tr><tr><td class="bg2"><b>Website</b>:</td><td class="bg2"><a href="<? echo $row['website']; ?>" target="_blank"><? echo $row['website']; ?></a></td></tr><tr><td class="bg1"><b>Sponsor Links</b>:</td><td class="bg1">
<script type="text/javascript"><!--
google_ad_client = "pub-8048181801684156";
//displays
google_ad_slot = "4239948836";
google_ad_width = 234;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
	</td></tr></tbody></table></p>


</div>



   </div>
</div>

<div id="footer">
© 2007 Mesquite Country Christmas

<br />
<br />

<script type="text/javascript"><!--
google_ad_client = "pub-8048181801684156";
//468x60, created 1/8/08
google_ad_slot = "0360766123";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


</div>

</div>
</body>
</html>
<?
}
?>

 

 

Where did I go wrong?

 

 

Link to comment
Share on other sites

You didn't execute the query.

 

<?php

include ('db_connect.php');

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT * FROM users WHERE id = $id;";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_array($result);
      $displayname = $row["displayname"];
      $displaytype = $row["displaytype"];
      $address = $row["address"];
      $city = $row["city"];
      $state = $row["state"]; 
      $postal = $row["postal"];
      $country = $row["country"];
      $rating = $row['rating'];
      $votes = $row['votes'];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }
}

?>

Link to comment
Share on other sites

That produces this error:

 

Parse error: syntax error, unexpected '}' in /home/mesquit1/public_html/local/displays.php on line 153

 

So remove this from the end of the file

 

<?
}
?>

 

 

That clears the error but I get no data displayed.

 

Is their something I need to add to the echo statements in the HTML about the ID?

Link to comment
Share on other sites

Ok I think that is working great like I needed, can't believe it was that easy.

 

Ok now how about this. I need to output whats in the database on this page.

 

http://mesquitechristmas.com/local/browse.php

 

To look like it does on this page.

 

http://mesquitechristmas.com/local/example.php

 

Here is the code I am using for the entire page. Now I can output data onto this page but the data is the same for every table row. I need each table row to be different like it is above. I am thinking their is something I need to add to the echo or something maybe?

 

<?php

include ('db_connect.php');

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT * FROM users WHERE id = $id;";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_array($result);
      $address = $row["address"];
      $city = $row["city"];
      $state = $row["state"]; 
      $postal = $row["postal"];
      $country = $row["country"];
    } else {
      die("No user found");
    }
  } else {
    die(mysql_error());
  }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Mesquite Texas Country Christmas" />
<meta name="keywords" content="Mesquite, Texas, Country Christmas" />
<meta name="author" content="NA" />
<link rel="stylesheet" type="text/css" href="/stylesheet.css" media="screen" title="FBC" />
<script type="text/javascript" src="drop_down.js"></script>
<title>A Mesquite Country Christmas</title>
</head>
<body>

<div id="wrap">

<a href="/index.html">
<img id="frontphoto" src="/images/header.png" width="760" height="237" alt="Mesquite Country Christmas" border="0"></a>

<div id="menu">

<h2 class="hide">Menu:</h2>

<ul id="avmenu">
<li><a href="/index.html">Home</a></li>
<li><a href="/christmasstory.html">The Christmas Story</a></li>
<li><a href="/directions.html">Directions</a></li>
<li><a href="#">Information</a><ul>
      <li><a href="/information.html">Display Facts & Info</a></li>
      <li><a href="/faq.html">FAQ</a></li>
      <li><a href="/playlist.html">2008 Playlist</a></li>
      <li><a href="#">Christmas History</a></li>
  </ul></li>
<li><a href="#">Photos</a>
  <ul>
      <li><a href="/2007photos.html">2007</a></li>
  </ul></li>
<li><a href="#">Videos</a>
  <ul>
      <li><a href="/2007videos.html">2007</a></li>
  </ul></li>
<li><a href="/guestbook.php">Guestbook</a></li>
<li><a href="/webcam.html">Web Cam</a></li>
<li><a href="/webradio.html">Internet Radio</a></li>
<li><a href="http://www.noradsanta.org/" TARGET="_blank">Track Santa</a></li>
<li><a href="/projects.html">Projects & How Tos</a></li>
<li><a href="/links.html">Links</a></li>
<li><a href="/contact_us.html">Contact Us</a></li>
</ul>

<center><img src="images/toys_for_tots.jpg" border="0" width="110" height="153" vspace="10"><a href="http://www.toysfortots.org/" TARGET="_blank"></a></center>

<center><a href="http://christmas.bronners.com/2007/house/534.html"><img src="http://christmas.bronners.com/voteforme/vote.jpg" border="0" width="110" height="153" alt="christmas decorations" vspace="10"></a></center>

</div>

<div id="content">

<b>Learn more about Display</b></a><br><br>> 
<div class="fadebox">

<h2>Mesquite Christmas Display Finder</h2>

<hr />

<p> Do you drive around aimlessly looking for Christmas lights every year? We are here to help make that tradition better by allowing you to search for local displays in Mesquite and get directions to them. And if you have a display of your own, you can add it to our database for others to find and enjoy!</p>


<p><span class="title">Current Displays In Mesquite</span><br /><table style="border-top: 1px solid rgb(51, 102, 51);" border="0" cellpadding="4" cellspacing="0" width="100%"><tbody><tr><td class="bg2" width="110">IMAGE</td><td class="bg2"><? echo $row['address']; ?><br><? echo $row['city']. "," . $row['state']. " " . $row['postal']; ?><br><? echo $row['country']; ?></td><td class="bg2" style="vertical-align: middle;">> <a href="displays.php?id=<?php echo $row['id']; ?>"><b>Learn more about Display</b></a><br><br>> <a href="http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=<? echo $row['address']; ?>&city=<? echo $row['city']; ?>&zipcode=<? echo $row['postal']; ?>&historyid=&submit=Get+Map" target="_NEW"><b>Get Directions</b></a><br /><br /></td></tr>
<tr><td class="bg1" width="110">IMAGE</td><td class="bg1"><? echo $row['address']; ?><br><? echo $row['city']. "," . $row['state']. " " . $row['postal']; ?><br><? echo $row['country']; ?></td><td class="bg1" style="vertical-align: middle;">> <a href="displays.php?id=<?php echo $row['id']; ?>"><b>Learn more about Display</b></a><br><br>> <a href="http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=<? echo $row['address']; ?>&city=<? echo $row['city']; ?>&zipcode=<? echo $row['postal']; ?>&historyid=&submit=Get+Map" target="_NEW"><b>Get Directions</b></a><br /><br /></td></tr></tbody></table></p>

</div>



   </div>
</div>

<div id="footer">
© 2007 Mesquite Country Christmas

<br />
<br />

<script type="text/javascript"><!--
google_ad_client = "pub-8048181801684156";
//468x60, created 1/8/08
google_ad_slot = "0360766123";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


</div>

</div>
</body>
</html>

 

-Thanks

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.