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
thefreebielife
Forum Contributor
Posts: 126 Joined: Thu Apr 26, 2007 2:59 pm
Post
by thefreebielife » Tue Jun 12, 2007 7:18 pm
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
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Tue Jun 12, 2007 7:30 pm
Where are $i and $r being assigned?
thefreebielife
Forum Contributor
Posts: 126 Joined: Thu Apr 26, 2007 2:59 pm
Post
by thefreebielife » Tue Jun 12, 2007 7:42 pm
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>
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Tue Jun 12, 2007 7:46 pm
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 » Tue Jun 12, 2007 7:50 pm
im using $r as a result function. $i was an error
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Tue Jun 12, 2007 7:59 pm
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 » Tue Jun 12, 2007 8:06 pm
i guess nowhere?
it seemed to work for me before though..
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Tue Jun 12, 2007 9:41 pm
thefreebielife wrote: it seemed to work for me before though..
When there were 0 records in the table it worked?