Jump to content

Passing Variables from a while loop to another PHP page


aleister1987

Recommended Posts

Hi all,

 

Im relatively new to PHP, and i have come across a brick wall. What im trying to do is pass two variables $factid and $pathid to another PHP page and from there insert them into SQL Table. The only problem is that the $pathid is inside a while loop and $factid is echoed on the page from another query.

 

Both variables are integers so im puzzled why they are not echoing back.

 

Here is some of the code from a page called firstfact.php

 

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("194.81.104.27","www","www") or die(mysql_error());

//select which database you want to edit
mysql_select_db("dbaleister") or die(mysql_error()); 

$search=$_POST["search"];

$factid = $_REQUEST["factid"];

//get the mysql and store them in $result.
//change whatevertable to the mysql table you're using.
//change whatevercolumn to the column in the table you want to search.

$result = mysql_query("SELECT * FROM fact,url,keyword WHERE factid = urlid AND factid = keyid AND title LIKE '%$search%'");

//grab all the content.

while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $factid=$r["factid"];
   $title=$r["title"];
   $paragraph=$r["paragraph"];
   $image=$r["image"];
   $keyid=$r["keyid"];
   $kword=$r["kword"];
   $urlid=$r["urlid"];
   $link=$r["link"];
   
   //display the row
   //echo "$title <br /> $paragraph";
}
?>

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("194.81.104.27","www","www") or die(mysql_error());

//select which database you want to edit
mysql_select_db("dbaleister2") or die(mysql_error());

$pathid = $_REQUEST["pathid"];

$result = mysql_query ("SELECT pathid FROM lp ORDER BY pathid DESC LIMIT 0,1");

  echo "<center><table border='1' width='50%' cellpadding='20px'>
    <tr>
      <td align='center' colspan='2'><b>YOUR CURRENT LEARNING PATH IS:</b></td>
    </tr>";
    while ($row = mysql_fetch_array($result)) { 
      echo "<tr>";
      echo "<td>" . $row['pathid'] . "</td>";
      echo "</tr>";
    }
  echo "</table></center>";
?>

 

 

Here is the next page called addfirstfact.php, this is all of code.

 


<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("194.81.104.27","www","www") or die(mysql_error()); 

//select which database you want to edit
mysql_select_db("dbaleister2") or die(mysql_error());


//GRAB THE VARIABLES

$pathid = $_REQUEST["pathid"];

$factid = $_REQUEST["factid"];


echo '$pathid';
echo '<br /><br />';
echo '$factid';
echo '<br /><br />';

//mysql_query("INSERT INTO step VALUES (null, '$factid', 0, 0, '$pathid', 0)");


header('Location: search2.php');

?>

 

 

If you need anymore information, let me know and i can send the whole of the page source code. or email me at devilsmaycrya@hotmail.com

 

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.