Problem with connection to different DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Problem with connection to different DB

Post by thefreebielife »

this is the first time ive done this- connect to a different DB on a server.

It didnt turn out so well. none of the info is displaying, only saying "there are no users". what did i do wrong?

Code: Select all

<?
$link = mysql_connect('mysql14.powweb.com', 'aa', 'aa');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('a100');
if (!$db_selected) {
    die('Could not select database: ' . mysql_error());
}
$query = 'SELECT username, ostatus FROM users';
$result = mysql_query($query);
if (!$result) {
    die('Query failed: ' . mysql_error());
} 

mysql_free_result($result);
?>
		      <tr bgcolor="#<?= ($i%2) ? 'FFE5B7' : 'FFEECC' ?>">
		      <Td>
		      <? echo $r["username"]; ?></Td>
		      <Td>
		      <? echo $r["ostatus"]; ?></Td>

<? 
			 if($i==0)
{
?>
 		      <tr>
		      <Td colspan=4 align="center"><FONT SIZE="2" COLOR="#FF0000"><B>No Users Reported</B></FONT></Td>
		      </tr>

<? } ?>  
feel free to laugh, i know this is a stupid problem but please help
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Where are $i and $r being assigned?
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

well even with this code it shows nothing:

Code: Select all

<?
$link = mysql_connect('mysql14.powweb.com', 'a100', 'a100');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('a100');
if (!$db_selected) {
    die('Could not select database: ' . mysql_error());
}
$query = 'SELECT username, ostatus FROM users';
$result = mysql_query($query);
if (!$result) {
    die('Query failed: ' . mysql_error());
} 

mysql_free_result($result);
?>
		      <tr bgcolor="#<?= ($i%2) ? 'FFE5B7' : 'FFEECC' ?>">
		      <Td>
		      <? echo $r["username"]; ?></Td>
		      <Td>
		      <? echo $r["ostatus"]; ?></Td>
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I still don't see where are the variables $i and $r being assigned in your script?
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

im using $r as a result function. $i was an error
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Where are you setting them though? They don't get assigned automatically
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

i guess nowhere?

it seemed to work for me before though..
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

thefreebielife wrote:it seemed to work for me before though..
When there were 0 records in the table it worked?
Post Reply