Jump to content

help passing along a VARIABLE from page to page


gigido

Recommended Posts

Hi,

i have an html page that is displaying the results of my query from a .php file. the results are displayed on the html page as

 

while ($row = mysql_fetch_array($result)) {

echo $row['title'].";

}

 

 

 

My question is if i were to pass along that data to another php page thats linked from this current html page, how would i pass the variable on? I tried doing a

$titleresults = $row['title']  but that doesnt seem to work.

 

 

any direction on how to do this would be appreciated.

 

thanks.

Link to comment
Share on other sites

What about having the results on a separate page and then just including it on whatever page you want.

 

table_data.php

<?php
// connect to database
$sql = "SELECT * FROM `table`";
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result)
if ($num_rows > 0)
{
$count = 0;
while ($row = mysql_fetch_array($result)
{
	$count++;
	echo ($count != $num_rows) ? "{$row['title']}, " : "{$row['title']}";
}
}
// close database connection
?>

 

index.php

<html>
<body>
<h1>Hello World!</h1>
<p><?php include('table_data.php'); ?></p>
</body>
</html>

 

another_page.php

<html>
<body>
<h1>Goodbye World!</h1>
<p><?php include('table_data.php'); ?></p>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.