Noskiw Posted January 3, 2009 Share Posted January 3, 2009 <?php $con = mysql_connect("localhost","115886","youtube"); $db = mysql_select_db(115886, $con); function f(){ $sql = "SELECT username FROM users"; $res = mysql_query($sql) or die(mysql_error()); echo "USERS:<br>"; $row = mysql_fetch_assoc($res); $sql2 = "SELECT id FROM users"; $res2 = mysql_query($sql2) or die(mysql_error()); $row2 = mysql_fetch_assoc($res2); echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<tr><td>Username</td><td>ID</td></tr>\n"; echo "<tr><td>".$row['username']."</td><td colspan=\"2\">".$row2['id']."</td></tr>\n"; echo "</table>\n"; } f(); ?> it returns one username and one id from my table. i know it's in a function. but who cares. this is quite annoying. but it was only a test. just to see if functions work. but i really want it to work properly. Quote Link to comment Share on other sites More sharing options...
Noskiw Posted January 3, 2009 Author Share Posted January 3, 2009 anyone? Quote Link to comment Share on other sites More sharing options...
Noskiw Posted January 3, 2009 Author Share Posted January 3, 2009 anyone? Quote Link to comment Share on other sites More sharing options...
DarkSuperHero Posted January 3, 2009 Share Posted January 3, 2009 you need to loop through the results....check this exmple from php.net out... <?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?> http://us.php.net/mysql_fetch_assoc other than that i think you will be all gravy....i gotta run otherwise i would try to set it to your specific code.... :-) cheers! Quote Link to comment 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.