Page 1 of 1

PHP Dynamic Pages

Posted: Mon Mar 08, 2010 12:15 pm
by tomtek1990
Hi All

I am new to PHP and i am trying to create a dynamicaly generated page for a localhost site i am making.

I have the databases working fine but i would like to be able to click on a button eg View and have it take me to a different page

Below is the code i have so far please help (IF YOU NEED MORE INFO PLEASE JUST ASK)

Thanks in advance

Database Page (Section)
{
echo "<tr>";
echo "<td><center>" . $row['ID'] . "</td>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td><center>" . $row['Certificate'] . "</td>";
echo "<td>" . $row['Director'] . "</td>";
echo "<td><center>" . $row['Released'] . "</td>";
echo "<td><center>" . $row['Notes'] . "</td>";
echo "<td><a href=\"View.php?id=".$row[ID]."\">View</a>";
echo "</tr>";
}

Dynamic Page

<?php
$db = mysql_connect("", "", "");
mysql_select_db("",$db);
$result = mysql_query("SELECT * FROM WHERE id=$ID",$db);
$row = mysql_fetch_array($result);
echo "Title: ".$row["Title"];
?>

I have removed the Database details

My Columns are - Title , Director, Certficate, Released and Notes

Please Help Guys

Thank you

Re: PHP Dynamic Pages

Posted: Mon Mar 08, 2010 1:18 pm
by tomtek1990
BTW when i click the View Button a page loads with the wanted result in the address bar I.E it says View.php?id=14

then it show Title: with no results from the Database

Please Help
:D

Re: PHP Dynamic Pages

Posted: Mon Mar 08, 2010 1:37 pm
by AbraCadaver
Where is $ID coming from? You need to read up on the $_GET and $_POST superglobals. Also, you don't have a table name in your query. Assuming that you have an `id` column and that you have a record with id = 14, then:

Code: Select all

$ID = (int)$_GET['id'];
$result = mysql_query("SELECT * FROM table_name WHERE id=$ID",$db);

Re: PHP Dynamic Pages

Posted: Mon Mar 08, 2010 2:13 pm
by John Cartwright
Also you need to use mysql_fetch_assoc() instead of mysql_fetch_array() is you want an associative array instead of a numerically indexed array.

Re: PHP Dynamic Pages

Posted: Mon Mar 08, 2010 2:20 pm
by AbraCadaver
John Cartwright wrote:Also you need to use mysql_fetch_assoc() instead of mysql_fetch_array() is you want an associative array instead of a numerically indexed array.
mysql_fetch_array() fetches both by default.