Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display content using content's ID

Status
Not open for further replies.

cabernet

Technical User
Feb 24, 2003
75
PK
Hello
I try to display content stored in my DB by using the following scripts
The first script (till capital letters) is called getdata.php
And works fine if I want to retrieve an image
However I now try to display text content in a table by using the very last line of that post bellow the capital text.
I cannot remember how to properly call the text by using its ID as the "trial" shows below
Thank you

regards

<?php
if($id) {
mysql_connect(&quot;-------&quot;);
mysql_checkerror();
mysql_select_db(&quot;------&quot;);
mysql_checkerror();
$query = &quot;select page_content from ----- where ----_id=$id&quot;;
$result = mysql_query($query);

$data = mysql_result($result,0,&quot;-----t&quot;);
Header(&quot;Content-type: text/php&quot;);
echo $data;
}
// functions

function mysql_checkerror(){

$err_no=mysql_errno();

if ($err_no > 0 ){

echo &quot;<h2> Error:</h1> &quot; . mysql_errno() . &quot;: &quot; . mysql_error() . &quot;<br>\n&quot;;

exit;

}
}
?>


IN A WEB PAGE: TO DISPLAY CONTENT STORED IN THE DB

echo '<a href=&quot;getdata.php?id=2&quot;>';



 
echo &quot;<a href='getdata.php?id=2'>Click</a>&quot; ;

When clicking this link, id=2 is passed to the getdata.php and the corrsponding record will be fetched.


(use $HTTP_GET_VARS[&quot;id&quot;] instead of $id in ur getdata.php)





--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Spookie
thank you it makes sense
but I wish my content (text) to be displayed as is in the html
not by cliking on, so maybe the href that calls a clickable link is not the formula
I try to populate my page by using the ID of stored data
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top