Rifts Posted November 27, 2009 Share Posted November 27, 2009 Using this code it will generate a short list from my database <?php mysql_connect('localhost','root',''); mysql_select_db("clients"); $fname = $_POST['firstname']; $SQL = "SELECT * FROM members WHERE firstname = '$fname'"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { print $db_field['firstname'] . "<BR>"; print $db_field['lastname'] . "<BR>"; print $db_field['email'] . "<BR>"; print $db_field['date'] . "<BR>"; echo $db_field['firstname']; } ?> but I need to be able to use the values its pulled out later down in the page. if I try to use echo $db_field['firstname']; somewhere else on my page it just leaves a blank spot... I tried doing this: <?php mysql_connect('localhost','root',''); mysql_select_db("clients"); $fname = $_POST['firstname']; $SQL = "SELECT * FROM members WHERE firstname = '$fname'"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $name = print $db_field['firstname'] . "<BR>"; $lname = print $db_field['lastname'] . "<BR>"; $mail = print $db_field['email'] . "<BR>"; $day = print $db_field['date'] . "<BR>"; echo $db_field['firstname']; } ?> and then using echo $thevariable i wanted but that didnt work either... thanks Link to comment https://forums.phpfreaks.com/topic/183100-storing-values-taken-from-a-db/ Share on other sites More sharing options...
cags Posted November 27, 2009 Share Posted November 27, 2009 $fields = array(); while ($db_field = mysql_fetch_assoc($result)) { $fields[] = $db_field; } Then wherever you need to use it... foreach($fields as $db_field) { print $db_field['firstname'] . "<BR>"; print $db_field['lastname'] . "<BR>"; print $db_field['email'] . "<BR>"; print $db_field['date'] . "<BR>"; } Link to comment https://forums.phpfreaks.com/topic/183100-storing-values-taken-from-a-db/#findComment-966419 Share on other sites More sharing options...
Rifts Posted November 27, 2009 Author Share Posted November 27, 2009 that worked perfectly thank you so much! Link to comment https://forums.phpfreaks.com/topic/183100-storing-values-taken-from-a-db/#findComment-966670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.