Solved

dynaimcally loading only a specific row using a URL query line

Posted on 2004-08-17
5
276 Views
Last Modified: 2008-03-06
I am engaged in a dynamic web publishing project and I am trying to get only a specific row in my mysql database to load onto a dynamic template for my dynamic website through the  use of URL query links on my static navigation page.  

My naviagation link looks somthing like this:

<a href="cccc2.php?id=1">

Which is intended to load row # 1 onto my template.

<a href="cccc2.php?id=2"> is supposed to load row #2 and no other rows. What I am getting is just a blank template or stupid excuses.

What I am running is the indigo package on windows 98SE which includes php4 with apache and mysql. The costom template uses the same database that was created for an experimental dixit template.

My template looks somthing like this:

<html><head>

<title>CCCC - Rural New Yorks Enviromental Watchdogs</title>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydixit",$db);
$id = $_GET['id'];
?>
</head><body background="img/woven.gif">
<p>
<div align="center">
  <table border="0" width="100%">
    <tr>
      <td width="100%">
        <p align="center"><font class="TimesRoman24" color="#000000" face="Times New Roman" size="5"><b><i>
        <p class="titre">
        <!--- Title PHP Begins --->
               <?php
                     $db = mysql_connect("localhost", "root");
                      mysql_select_db("mydixit",$db);
                      $id = $_GET['id'];
                      $sql = "SELECT title
                              WHERE 'id'=$id
                              AND $id = $_GET['id']
                              FROM dixit_pages"  
                  $result = mysql_query("SELECT title FROM dixit_pages,$db);
                  echo "<table border=0 td=100%>\n";
                  printf("%s\n",
                  $myrow["title"]);
                  echo "</table>\n";
                  ?>
        <!--- Title PHP Ends --->
      </p></font></td>
    </tr>
  </table>
</div>
<div align="left">
  <table border="0" width="39%">
    <tr>
      <td width="33%"><font class="TimesRoman10" color="#000000" face="Times New Roman"><i>updated:
        </i></font></td>

      <td width="67%"><font class="TimesRoman10" color="#000000" face="Times New Roman"><i>


<!--- Date Posted --->

               <?php

               $db = mysql_connect("localhost", "root");
               mysql_select_db("mydixit",$db);
               $id = $_GET['id'];

               $result = mysql_query(" WHERE id=$id SELECT DATE FROM dixit_pages",$db);

                 echo "<table border=1 td=100%>\n";

                 printf("%s\n",
                  $myrow["DATE"]);


                  echo "</table>\n";

                   ?>




<!--- startDate Ends! --->




</i></font></td>
    </tr>
  </table>
</div>
<p>&nbsp;</p>
<table border="0" width="113%">
  <tr>
    <td width="100%">
      <p align="center"><p class="texte">

<!--- PHP Content Begins! --->
     
     
     
               <?php

               $db = mysql_connect("localhost", "root");
               mysql_select_db("mydixit",$db);
               $id = $_GET['id'];

                $result = mysql_query("WHERE id = $id SELECT content FROM dixit_pages",$db);

 
                  echo "<table border=0 td=100%>\n";
                 

                 printf("%s\n", $myrow["content"]);


                  echo "</table>\n";

                 ?>
     
     
<!--- PHP Content Ends! --->  
     
      </p></td>
  </tr>
</table>
<p align="left"><font class="TimesRoman10" color="#000000" face="Times New Roman" size="2">
<a href="http://www.homestead.com/concernedcitizens/index.html" target="_self">
<i>Concerned Citizens of Cattaragus County </i></a>

If anyone could help me with this it would be greatly appreciated.



0
Comment
Question by:shoeboxxpc
5 Comments
 
LVL 1

Accepted Solution

by:
C7Swill earned 50 total points
ID: 11827802
shoeboxx,

your problem is the way you are getting your info from the database

A well formed php mysql database query would look like this.

$sql = mysql_query("SELECT what FROM database WHERE field='$_GET[variable]'")  
$result = mysql_fetch_array($sql);

in your case:

$sql = mysql_query("SELECT title, date, content FROM dixit_pages WHERE id='$id'")  
$result = mysql_fetch_array($sql);

You can then reference the title by

echo $result['title'];
echo $result['date'];
echo $result['content'];

title, content and date must be columns in your mysql database.


Try this code:

// Start Code
// Connect
$db = mysql_connect("localhost", "root");
mysql_select_db("mydixit",$db);
// Convert Get Id
$id = $_GET['id'];
// Select Page
$sql = mysql_query("SELECT title, date, content FROM dixit_pages WHERE id='$id'");
// Put into array
$result = mysql_fetch_array($sql);
// Echo
echo $result['title'];
echo $result['date'];
echo $result['content'];
// End Code


--Sean
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Read about why website design really matters in today's demanding market.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now