Forum Moderators: coopster
I have a php page that will display the current mysql contents by "subject" & "date" only (and not all details yet)
Once a reader likes to read more about a subject(which will be a clickable link)then that action should open up another php page that will automatically access database at that moment and display the "message" that is being requested by reader.
here is how i am trying to do it but i can not get the last part right.plz help.
// set database server access variables:
$host = "#*$!#*$!";
$user = "yyyy";
$pass = "zzzzz";
$db = "mmmmmmm";
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM MYTABLE";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// print them one after another
echo "<table cellpadding=10 border=1>";
while(list($Date,$FirstName,$LastName,$Email,$Subject,$Message) = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td><a href= '$Message? value=$Subject'> $Subject </a> </td>";
echo "</tr>"; }
echo "</table>"; }
i AM able to display correct links with mysql table subjectwise (and up to date) but once i click the link,its not giving me message part.Another way would be to pass a value(which i tried but not sure how to exactly do here) to another page and use that value with $GET and compare it with lets say date value in database and if its a match,then display that message.
any help would be appreciated.
thanks
<?php
# GRAB THE VARIABLES FROM THE URL
$DateNew = $_GET['Date'];
echo "$DateNew";
// set database server access variables:
$host = "BBBBBB";
$user = "#*$!#*$!X";
$pass = "YYYYYYY";
$db = "ZZZZZZZ";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM MYTABLE";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
if ($DateNew == $Date){
echo "$Message";}
else
{ echo" THIS IS WRONG LINK";
?>
I tend to use braces whenever I am embedding PHP variables in a double-quoted string:
echo "<td><a href= '{$Message}? value={$Subject}'> $Subject </a> </td>"; I am trying to do this using this code:
while(list($Date,$FirstName,$LastName,$Email,$Subject,$Message) = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td><a href= '$Message? value=$Subject'> $Subject </a> </td>";
I can also see value being passed on next page in the browser,but page2 will not display message linked to that value in table (however its been able to show the table and anything else on page2)
plz help
http://example.com/Folder1/page2.php?%20value=5
my question is"What is that %20 ? as I am only trying to transfer value = 5,but why is my page2 not picking up this value ?
Here is my page2 by the way:
<?php if (isset($_GET['value'])):
{
$Date = value;
echo "<p> $Date </p>"; //just to check if it displays value here
$Counter = 0 ;
echo "<table cellpadding=40 border=3>";
while($Counter <=2)
{ echo "<tr>";
echo '<td> "The value of this is: ".$Date </td>';
echo "</tr>";
$Counter++;
}
echo "</table>";
}
?>
[edited by: eelixduppy at 1:30 am (utc) on June 21, 2008]
[edit reason] changed to example.com [/edit]
echo "<td><a href= '{$Message}? value={$Subject}'> $Subject </a> </td>"; $href = "{$Message}?" . htmlentities('value=' . urlencode($Subject));
echo "<td><a href=\"{$href}\">" . htmlentities($Subject) . "</a></td>"; <?php
if (isset($_GET['value'])) {
$Date = $_GET['value'];
}