Solved

dynaimcally loading only a specific row using a URL query line

Posted on 2004-08-17
5
283 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

770 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