How do I pass variables from mysql_fetch_array to another PHP program?

Question by mistatom: How do I pass variables from mysql_fetch_array to another PHP program?
I’m not a programmer, but I do understand a little bit of PHP. My problem is that I’m taking two program snippets that work well, but when I try to pass variables from the first one to the second, something breaks and nothing comes out.

The first part of the program selects a random record from a MYSQL database.

// Create the connection and select the DB
$ link = mysql_connect(“localhost”,”root”,””);

if ($ link) {
mysql_selectdb(“test”,$ link);

// Select records from the DB
$ query = “SELECT * FROM names ORDER BY Rand() LIMIT 1”;
$ result = mysql_query($ query);

// Display records from the table
echo “

“;
while ($ row = mysql_fetch_array($ result, MYSQL_NUM)) {

The second part of the program uses XML RPC to post remotely to a WordPress blog.

$ wp = new eWordpressApi(“http://www.mysite.com/xmlrpc.php”,”myname”,”mypass”);
$ title = “Testing”;
$ text = “Lorem Ipsum”;
$ category = array(Pants,Stuff); // Assuming you have categories with IDs: 1,2
$ postID = $ wp->newPost($ title,$ text,$ category);
if(is_array($ postID)) echo “Die, damn bug!”;

I’ve been trying to pass the results from mysql_fetch_array to the second program so that $ title = row[0] and $ text = row[1], row[2], but when I execute the script all it does it print the second program as text instead of passing the variable and executing the program.

I’ve been beating my head against the wall for a week on this problem. What am I doing wrong.

The complete program:

“;
while ($ row = mysql_fetch_array($ result, MYSQL_NUM)) {

$ wp = new eWordpressApi(“http://www.mysite.com/xmlrpc.php”,”myname”,”mypass”);
$ title = “Testing”;
$ text = “Lorem Ipsum”;
$ category = array(Pants,Stuff); // Assuming you have categories with IDs: 1,2
$ postID = $ wp->newPost($ title,$ text,$ category);
if(is_array($ postID)) echo “Die, damn bug!”;

}

?>

Best answer:

Answer by –jrom–
use the include_once( ) function in PHP so you could have the variables from the previous page in the second page.

Example, your page1.php queries to the database and stores it mysql_fetch_array[] variable, to be able to use mysql_fetch_array[] in the next page(page2.php), use

include_once(page2.php);

hope this helps

Give your answer to this question below!

Revisions

There are no revisions for this post.

Tags: , , , , ,

No comments yet.

Leave a Reply