Jump to content


Photo

Help me please, im not very good with mysql.


  • Please log in to reply
5 replies to this topic

#1 Doomflame

Doomflame
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 10 May 2003 - 11:27 PM

I told it to select username from phpbb_users, and it should select multiple values. how would i make these values print on the page? I need all of them to print. Here is the code i have so far in case it helps:


$mysql = mysql_connect("localhost", "doomflam_admin", "PASSWORD") or die("Could Not Connect To Database!");

mysql_select_db("doomflam_forum");

$query = "SELECT username FROM phpbb_users";

$setquery = mysql_query($query);

$res = mysql_fetch_array($setquery);

foreach($res as $key => $value) {

 print "$value <br>";

}


And this outputs:

Doomflame  
Doomflame


Doomflame is the first username in the list, but i need it to list all of them.

#2 BK87

BK87
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts
  • LocationPhiladelphia, PA

Posted 11 May 2003 - 12:10 AM

Try this:
[php:1:6823e43252]<?php
//Databaseinfo
$database=\"db\";
$db = mysql_connect(\"localhost\",\"user\",\"pass\");
mysql_select_db($database);
//Code
$listm = mysql_query(\"SELECT * FROM contest_users\") or die (mysql_error());
while ($row = mysql_fetch_array($listm)) {
print(\"$row->username\");
}
?>[/php:1:6823e43252]

Use $row to select the row that you want, like username, or pass...

Hope it helps

#3 Doomflame

Doomflame
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 May 2003 - 12:31 AM

nope, this time it didn\'t show any names.

#4 BK87

BK87
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts
  • LocationPhiladelphia, PA

Posted 11 May 2003 - 12:40 AM

try this it works on my box.. as a matter a fact I\'m using it
[php:1:eca989abab]<?php
//Settings
$server=\"localhost\";
$database=\"db\";
$username=\"user\";
$pass=\"pass\";
$table=\"table\";

//Code
$db = mysql_connect($server,$username,$pass\");
mysql_select_db($database);
$list = mysql_query(\"SELECT * FROM $table\") or die (mysql_error());
while ($row = mysql_fetch_array($list)) {
print(\"$row[usernme]\");
}

?>[/php:1:eca989abab]

Again chage username to what ever field you have.. this works on my box, if it don\'t on yours, then I suggest you get another one.

#5 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 11 May 2003 - 12:43 AM

Try this:
$mysql = mysql_connect("localhost", "doomflam_admin", "PASSWORD") or die("Could Not Connect To Database!");

mysql_select_db("doomflam_forum",$mysql) or die("Unable To Locate Database!");

$query = "SELECT username FROM phpbb_users";

$setquery = mysql_query($query) or die("Query failed!");



if (mysql_num_rows($setquery)>0)

{

  while ($res = mysql_fetch_array($setquery))

  {

    print $res[\'username\']."<br>rn";

  }

}

else

{

  print "There are no entries!";

}

Hope that helps.

You can break it down if you need to customize it.. let us know if you need more help.

edit // posted late.. either method will work. :)

#6 Doomflame

Doomflame
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 May 2003 - 12:46 AM

metalblend, thanks it works!!!!!!!!!!!!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users