I am trying to try echo an article column on a page called article.php based on the ID of an item which is inserted into a link from the previous page. However, I am struggling to show the article. I can only echo the ID.
I’m not quite sure what you have in mind. Is the information store in a database? If so you could simply retrieve the content from the database based on the ID and display it using echo.
Yes the information is stored in a database, but I dont know how to retreive the information to display it. Do I need to query the database to retrieve the information, if so do you know what code I need to do this please?
Yes you would. Sound as if you are new with this so I think best to start by learning a bit about database as well as PHP since this will be the language you use. Take a look at this tutorial and see if it helps. MySQL is used for the tutorial. If your database is not that then just Google it and I’m sure you will find them too. Post up additional info about your site if you could. Perhaps other members will offer suggestions.
Many thanks, I have been watching a number of YouTube videos. I shall also read through this.
The frustrating thing is I can echo everything if I put it into the URL such as this article.php?ID=<?php echo $row[‘ID’]; ?>&content=<?php echo $row[‘content’]; ?>…
It does work but it looks messy.
But if I use just the ID article.php?ID=<?php echo $row[‘ID’]; ?> I cant work out how to echo the content.
Hi,
For what you need , you must perform a Select in the database to get the row with data associated to that ID.
$sql = "SELECT * FROM table_name WHERE ID =". intval($_GET['ID']]). " LIMIT 1";
Than execute this query, and echo $row[‘article’] .
Well, try learn about mysql and php if you work with database, here’s a tutorial about Select PHP-MySQLi.
The frustrating thing is I can echo everything if I put it into the URL such as this article.php?ID=<?php echo $row[‘ID’]; ?>&content=<?php echo $row[‘content’]; ?>…
Can you give us the links to what you’re talking about?
I now have the following code but it says: Invalid query: Query was empty
<?php
$sql = "SELECT * FROM articles WHERE '". mysql_real_escape_string($ID) ."'";
$rs = mysql_query($strSQL);
if (!$strSQL) { // add this check.
die('Invalid query: ' . mysql_error());
}
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
echo $row['title'] . "<br />";