PHP Dynamic Pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomtek1990
Forum Newbie
Posts: 2
Joined: Mon Mar 08, 2010 12:10 pm

PHP Dynamic Pages

Post 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
tomtek1990
Forum Newbie
Posts: 2
Joined: Mon Mar 08, 2010 12:10 pm

Re: PHP Dynamic Pages

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Dynamic Pages

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP Dynamic Pages

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Dynamic Pages

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply