- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
So this is my code:
$connect = mysql_connect("host", "username", "password");
$select_db = mysql_select_db("database", $connect);
if(!$select_db){
die(mysql_error());
}
$write = mysql_query("SELECT username FROM husers");
?>
The users are:
The result is:
“The users are: Resource id #3”
What am I doing wrong?
Oh, and please note that I don’t know PHP at ALL. This is basically a mix up of codes and tuts I found around the web, that weren’t working and my logic.
My desire:
To list all of the “username”s in the table “husers” on the page.
The reason why you’re getting “The users are: Resource id #3” is because whenever you do a query you always have to fetch the table. This is what the code should have looked like.
< ?php
$connect = mysql_connect("host", "username", "password");
$select_db = mysql_select_db("database", $connect);
if(!$select_db){
die(mysql_error());
}
$write = mysql_query("SELECT username FROM husers");
$users = "";
while ($row = mysql_fetch_assoc($write)) {
$users = $row;
}
?>
Then you would have to do this.
< ?php
$connect = mysql_connect("host", "username", "password");
$select_db = mysql_select_db("database", $connect);
if(!$select_db){
die(mysql_error());
}
$write = mysql_query("SELECT username FROM husers");
$users = "";
while ($row = mysql_fetch_assoc($write)) {
$users .= "- " . $row . "
";
}
?>
I forgot to close the li tag, make sure you close it.
EDIT: I updated the code to close the li tag.