PSTCAT
asked on
Displaying a single Database table row in php
Ok, bascially, what I am trying to achieve is a piece of text that says
"Parties in CITY now"
The "CITY" is the place the user has entered in their account information and sent it to the database.
So I want to display that city row from the table on my website.
Here is my code for this,
I get an error with
So I replaced the [ ] with ( ) it gets rid of the error
but doesn't display anything on my page.
Any thoughts?
Thanks.
"Parties in CITY now"
The "CITY" is the place the user has entered in their account information and sent it to the database.
So I want to display that city row from the table on my website.
Here is my code for this,
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
$result = mysql_query("SELECT * FROM user");
while($row = mysql_fetch_assoc($result)){
echo " ".$row['City'].";
}
I get an error with
echo " ".$row['City'].
So I replaced the [ ] with ( ) it gets rid of the error
but doesn't display anything on my page.
Any thoughts?
Thanks.
ASKER
Thanks,
but now I get
Fatal error: Using $this when not in object context
but now I get
Fatal error: Using $this when not in object context
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect. Thank you!
ASKER
Cheers.
$user = $this->real_escape_string(
$city = $this->query("SELECT City FROM users WHERE user = '" . $user . "'");
if ($city->num_rows > 0){
$row = $city->fetch_row();
return $row[0];
} else
return null;
}