mysql - PHP pass variable value form one php to another php -



mysql - PHP pass variable value form one php to another php -

i new php code, know how pass multiple variable info 1 php file php file. below detailed description.

in first file (file1) have assigned query value want read in sec file( file 2). please help. below code

file 1:

$query = "select * table1 field1 = 'abc' , feild2='xyz'"; $query1 = "select * table2 field1= 'abc' , feild2='xyz'"; $query2 = "select * table3 field1= 'abc' , feild2='xyz'"; <a target="_blank" href='file2.php' >firstquery</a> <a target="_blank" href='file2.php' >seconquery</a> <a target="_blank" href='file2.php' >thirdquery</a>

file2:

echo $query; echo $query1; echo $query2;

you need utilize parameters in links if understanding question correctly. not however, want pass entire query or save query session. instead want pass values need query. maintain queies maintained in 1 place create sort of model class or set of functions included in files need them.

<?php // initial page $field1 = 'abc'; $field2 = 'xyz'; $query = "select * table1 field1 = ? , feild2=?"; $query1 = "select * table2 field1= ? , feild2= ?"; $query2 = "select * table3 field1= ? , feild2= ?"; ?> <a target="_blank" href="<?php printf('file1.php?field1=%s&field2=%s', $field1, $field2) ?>" >firstquery</a> <a target="_blank" href="<?php printf('file2.php?field1=%s&field2=%s', $field1, $field2) ?>">seconquery</a> <a target="_blank" href="<?php printf('file3.php?field1=%s&field2=%s', $field1, $field2) ?>">thirdquery</a>

then in file*.php

<?php // file1.php $field1 = isset($_get['field1']) ? $_get['field1'] : null; $field2 = isset($_get['field2']) ? $_get['field2'] : null; $query = "select * table1 field1 = ? , feild2=?"; $query1 = "select * table2 field1= ? , feild2= ?"; $query2 = "select * table3 field1= ? , feild2= ?"; $db = new pdo($dsn, $user, $pass); if ($field1 && $field2) { // querying // if not using pdo or mysqli supports prepared statments // need manually quote these variables since come frontend // want sanitize of validate them in way well. $stmt = $db->prepare($query); $stmt->execute(array($field1, $field2); $results1 = $pdo->fetchall(pdo::fetch_assoc); // rinse , repeat other 2 queries } ?>

php mysql

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -