Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    echo stuff out from the database

    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 Code:

    <?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(
    $usernamerandom_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

  • #2
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •