jesushax Posted February 20, 2008 Share Posted February 20, 2008 hi me again, asp response.write recordset("RecordName") whats the php equviliant to writing data from a mysql database Quote Link to comment https://forums.phpfreaks.com/topic/92082-write-mysql-record/ Share on other sites More sharing options...
jesushax Posted February 20, 2008 Author Share Posted February 20, 2008 found it its $row yes sooooo my connection.php file <?php $uname = 'username'; $pass = 'password'; $db_name = 'database name'; $host = 'host'; $con = mysql_connect($host, $uname, $pass); if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($db_name, $con); if (!$db_selected) { die ('Can\'t use database : ' . mysql_error()); } ?> then in my page <?php include("/includes/connection.php"); ?> <?php mysql_query("SELECT * FROM tblUsers");while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }mysql_close($con); ?> this is how its done yes? Quote Link to comment https://forums.phpfreaks.com/topic/92082-write-mysql-record/#findComment-471551 Share on other sites More sharing options...
duclet Posted February 20, 2008 Share Posted February 20, 2008 You might want to set the result of mysql_query to $result before you do anything. Also, are you asking about writing or reading from the database? A SELECT is just reading information from the database. You are not actually writing anything. Quote Link to comment https://forums.phpfreaks.com/topic/92082-write-mysql-record/#findComment-471562 Share on other sites More sharing options...
jesushax Posted February 20, 2008 Author Share Posted February 20, 2008 how do i do this? i know sql syntax im asking about writing the results of the select to the screen and i do this how? thanks Quote Link to comment https://forums.phpfreaks.com/topic/92082-write-mysql-record/#findComment-471583 Share on other sites More sharing options...
duclet Posted February 20, 2008 Share Posted February 20, 2008 What you currently have is mostly right, just change it to this: <?php include("/includes/connection.php"); $result = mysql_query("SELECT * FROM tblUsers"); while($row = mysql_fetch_assoc($result)) { printf('%s %s<br />', $row['FirstName'], $row['LastName']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/92082-write-mysql-record/#findComment-471959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.