...

View Full Version : echo stuff out from the database



Jon W
01-11-2008, 04:06 AM
What are some good ways to echo the stuff out of the database. And before you laugh at this code, yes I am a 'Noob' at coding PHP. If I wasn't I wouldn't be asking this question. :P So heres what I've came up with some far. I start a mysql_query and select the stuff that I wanted to to get out of the database. Then (I'm guessing on this part) I use a if statement to see if mysql_num_rows equals to atleast one. If it comes up true then I call in mysql_fetch_assoc($query), and actually its more like $results = mysql_fetch_assoc($query); and then I take the variable $results and echo or print it onto the page. So the script would look something like this:




<?php
include("db.php");

$query = mysql_query("SELECT username, random_key FROM users") or die('Database error: ' mysql_error());

if(mysql_num_rows($query) == 1)

{

$results = mysql_fetch_assoc($query);

list($username, random_key);

echo "Username: $username | Random Key: $random_key";

}

?>



Am I right? If so tell me a way that its suppose to be done.

Thanks
Jon W

o0O0o.o0O0o
01-11-2008, 04:20 AM
Am I right? If so tell me a way that its suppose to be done.

I think you should have known from your output that you r right or wrong :)

Just search google for some basic php -myql tutorial and you will get plenty.Initially
you will have so many small erros , Googling and reading online articles is best

It will save your time as well

http://www.freewebmasterhelp.com/tutorials/phpmysql/1



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum