FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


mysql_fetch_array probelm





ncwdavid
Hey,
I am trying to show the latest 5 members to signup in my site on the homepage but i am having a bit of a problem. Here is what code i have written to get the latest 5 members in an array.
Code:

<?php
   $sql_members = mysql_query("SELECT username FROM users WHERE active='1' ORDER BY user_id DESC");
   $members = mysql_fetch_array($sql_members);
   echo "$members[0]<br>$members[1]<br>$members[2]<br>$members[3]<br>$members[4]"?>


When i run that sql query in phpmyadmin it comes up just like i want it but then when i try to make it into an array like above it doesnt work. The only thing that comes up on the page in the $members[0] array but the rest dont. Any ideas?
ncwdavid
Its all right now i just figured it out. here is what i did:
Code:

<?php
   $sql_members = mysql_query("SELECT username FROM users WHERE active='1' ORDER BY user_id DESC LIMIT 5");
   while ($row = mysql_fetch_row($sql_members)) {
    foreach ($row as $value) {
        echo "<p>$value</p>";
    }
    }
   ?>
vignesh_natraj
Code:
<?php
   $sql_members = mysql_query("SELECT username FROM users WHERE active='1' ORDER BY user_id DESC");
   $members = mysql_fetch_array('$sql_members');
   echo (" $members[0]; "<br>" $members[1];"<br>" $members[2];"<br>"$members[3];"<br>" $members[4]; "); ?>

you can also try this put a semicolon at end of each variable. also use double quotes to differenciate between HTML and PHP
Related topics
script backup database
survey Insert in Php
MSN messenger error
HTTP AUTH with PHP and mySQL
Build an online dictionary by PHP/MySQL
Make search engine With PHP and mySQL, for your site
lightning strikes
Implementing your database access in PHP as a layer.
pOINTS
Warning: mysql_fetch_array():Help me........
Using mysql_fetch_array()
Help me find the error in my code... mysql_fetch_array():
Mysql seach for 4 argument or 1 or any conbination of them??
mysql_fetch_array().... pissing me off!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.