ngreenwood6 Posted July 31, 2008 Share Posted July 31, 2008 I am trying to pull data from my mysql database which looks like this: Database:news table:users Inside of the table is this: email firstname lastname I have three files: the first one is list.php <?php //include the variables include ("variables.php"); include ("db.php"); //connect to database $mysql_connect = mysqli_connect($host,$db_user,$db_pass,$db_name) or die ("Could not connect to database"); //variable to get data to the database $result = mysqli_query($mysql_connect,$getfrom_db) or die ("Error: ".mysqli_error($mysql_connect)); $info = mysqli_fetch_array($result); $email = $info['email']; echo ("$email"); ?> The second one is variables.php: <?php //define the variables $get_email = Trim(stripslashes($_POST['get_email'])); $get_firstname = Trim(stripslashes($_POST['get_firstname'])); $get_lastname = Trim(stripslashes($_POST['get_lastname'])); ?> the last one is db.php: <?php //database connection settings $host = "localhost"; $db_name = "news"; $db_table = "users"; $db_user = "root"; $db_pass = ""; //email addresses from database $putinto_db = "INSERT INTO users (email,firstname,lastname) VALUES ('$get_email','$get_firstname','$get_lastname')"; $getfrom_db = "SELECT email FROM users"; //used for the connection to get email addresses from database $email = $info['email']; ?> I am trying to have it list all of the email addresses in the database. I have it working but only to a certain extent. It will list one of the email addresses. Can someone please tell me what im doing wrong? Link to comment https://forums.phpfreaks.com/topic/117603-list-mysql-items/ Share on other sites More sharing options...
cooldude832 Posted July 31, 2008 Share Posted July 31, 2008 I don't see any select queries those are how you "select" stuff outta a database Link to comment https://forums.phpfreaks.com/topic/117603-list-mysql-items/#findComment-604913 Share on other sites More sharing options...
ngreenwood6 Posted July 31, 2008 Author Share Posted July 31, 2008 In the last file their is a variable named "$getfrom_db" that selects their email from the table users. I said it works but it only displays one. Link to comment https://forums.phpfreaks.com/topic/117603-list-mysql-items/#findComment-604923 Share on other sites More sharing options...
cooldude832 Posted July 31, 2008 Share Posted July 31, 2008 you need to look at basic mysql tutorials (and adjust for the mysqli differences) its a very simple <?php $q = "Select * from `table"; $r = mysql_query($q) or die(mysql_error()."<br /><Br />".$q); while($row = mysql_fetch_assoc($r)){ print_r($row); ?> Link to comment https://forums.phpfreaks.com/topic/117603-list-mysql-items/#findComment-604928 Share on other sites More sharing options...
ngreenwood6 Posted July 31, 2008 Author Share Posted July 31, 2008 That was the point of me coming here so that I could get the help that I need. I tried looking at tutorials but sometimes a little help from above is nice. could you someone show me how to incorporate this into my code. Thanks Link to comment https://forums.phpfreaks.com/topic/117603-list-mysql-items/#findComment-604938 Share on other sites More sharing options...
ngreenwood6 Posted July 31, 2008 Author Share Posted July 31, 2008 I really need some help with this if anyone has any suggestions or any help is greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/117603-list-mysql-items/#findComment-604957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.