samoi Posted November 8, 2008 Share Posted November 8, 2008 Hello guys, how are you? again, I've been working in a one-line code to get it work, but I think I have some mistake! for example, let's say I have this code: <? $con = mysql_connect("localhost","root","password") or die("Error connecting!"); $db = mysql_select_db("this_db") or die("Couldn't find the DB"); $samoi = $db->query_first("SELECT * FROM users WHERE id <= '10'"); // this is going to get info from id 1 to 10, right? echo $samoi['username']; echo "<br>"; echo $samoi['password']; echo "<br>"; echo $samoi['email']; ?> I tried it, but it only brings Quote Link to comment https://forums.phpfreaks.com/topic/131865-solved-how-to-create-a-mysql-query-in-a-php-page/ Share on other sites More sharing options...
.josh Posted November 8, 2008 Share Posted November 8, 2008 Try this: <?php $con = mysql_connect("localhost","root","password") or die("Error connecting!"); $db = mysql_select_db("this_db") or die("Couldn't find the DB"); $sql = "SELECT * FROM users WHERE id <= '10'"; // this is going to get info from id 1 to 10, right? $result = mysql_query($sql) or die(mysql_error()); echo "username password email <br />"; while ($samoi = mysql_fetch_assoc($result)) { echo $samoi['username']; echo " "; echo $samoi['password']; echo " "; echo $samoi['email']; echo "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131865-solved-how-to-create-a-mysql-query-in-a-php-page/#findComment-685033 Share on other sites More sharing options...
php-pendejo Posted November 8, 2008 Share Posted November 8, 2008 ok what are you trying to get a list of users and other information or just 1 user and info??? for more then 1 thing i would do this $con = mysql_connect("localhost","root","password") or die("Error connecting!"); $db = mysql_select_db("this_db") or die("Couldn't find the DB"); $result = $db->query_first("SELECT * FROM users <=10"); // this is going to get info from id 1 to 10, right? while(list($username, $password, $email) = mysql_fetch_array($result)) { echo $username; echo "<br>"; echo $password; echo "<br>"; echo $email; } this will loop thro and list all you variables 1 thro 10 Quote Link to comment https://forums.phpfreaks.com/topic/131865-solved-how-to-create-a-mysql-query-in-a-php-page/#findComment-685036 Share on other sites More sharing options...
samoi Posted November 8, 2008 Author Share Posted November 8, 2008 Thank you guys always helpful Quote Link to comment https://forums.phpfreaks.com/topic/131865-solved-how-to-create-a-mysql-query-in-a-php-page/#findComment-685592 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.