html - How do I return the result of a database query through a php variable to another page using the include function -


i trying occupy html div of page results of database query page via php echo command. here sample code: page performing query

$content = '<h3>member login</h3> <?php     //step 3: perform db query     $member_info = mysql_query("select * members", $db_connect); ?> <?php     // step 4: use returned data     while($row = mysql_fetch_array($member_info)){         echo "first name: ".$row[1];         echo "last  name: ".$row[2]."<br>";         echo "user  name: ".$row[3]."<br>";         echo "password  : ".$row[4]."<br>";         echo <hr>;     } ?> '; include 'foundation.php'; 

this page issuing echo command(foundation.php):

<div id="content">      <?php          echo $content;     ?>  </div><!--end content div--> 

the database connection established on page know not issue. believe problem syntax because displays following:

"; echo "user name: ".$row[3]." "; echo "password : ".$row[4]." "; echo ; } ?>  

indeed, have syntax problems. can't put php inside string, , expect php execute when echo string later on. instead have static string. functions , constructs interpreted plain text, , lose php magic.

to create $content, try this:

<?php $content = '<h3>member login</h3>'; $member_info = mysql_query("select * members", $db_connect); while($row = mysql_fetch_array($member_info)){     $content .= "first name: ".$row[1];     $content .= "last  name: ".$row[2]."<br>";     $content .= "user  name: ".$row[3]."<br>";     $content .= "password  : ".$row[4]."<br>";     $content .= "<hr>"; } include 'foundation.php'; ?> 

just note... mysql_* functions deprecated. instead, should use mysqli or pdo. see why shouldn't use mysql_* functions in php?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -