using 2 databases

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

Ok, im going to head this towards a different route. Im using this code

Code: Select all

if($_GET['action'] == 'members')
{
$result = mysql_query("SELECT Uname FROM `loginphp` WHERE `Guild` = '{$_SESSION['Guild']}'") or die(mysql_error());
echo "<center>";
echo "<table><tr><td><b>Username</b></td><td><b>Character Name</b></td></tr>";
if($_GET['action'] == '')
{
header("Location:?action=nextpage&id=1");
}
if($_GET['action'] == 'nextpage')
{
// Print out the contents of the entry
$num=mysql_numrows($result);
$strBGColor = '#EAF1FF';
$i=0;
while ($i < $num)
{
$number = $number + 1;
$number2 = 25;
$id = $_GET['id'] + 1;
$id3 = $_GET['id'] - 1;
$id2 = $_GET['id']*$number2;
if($number < (($id3*$number2)+1) || $number > $_GET['id']*$number2)
{
$row = mysql_fetch_array( $result );
$i++;
$number4 = $number;
}
else
{
if($strBGColor == '#EAF1FF')
{
$strBGColor = '#8ab4ff';
}
else
{
$strBGColor = '#EAF1FF';
}
$row = mysql_fetch_array( $result );
echo "<tr bgcolor='$strBGColor'><td>";
echo "" . $row['Uname'] . "</td><td>";
echo "" . $row['Cname1'] . "</td></tr>";
$i++;
$username = $row['Uname'];
}
}
}
echo "</table>";
$next = $_GET['id'] + 1;
$back = $_GET['id'] - 1;
if($_GET['id'] == '1')
{
echo "<a href=?action=nextpage&id=$next>next</a>";
}
if($_GET['id'] > '1')
{
if($_GET['id'] < ($number4/$number2))
{
echo "<a href=?action=nextpage&id=$back>back</a> | <a href=?action=nextpage&id=$next>next</a>";
}
else
{
echo "<a href=?action=nextpage&id=$back>back</a>";
}
}
if($username == '')
{
echo "<a href=?action=nextpage&id=$back>back</a>";
}
}
to search the member table, called loginphp, for all the Uname (user names) that have the guild SLX in the guild field, matching my session guild, which is slx, and set when i log in. I know the session is set correctly because i use this same thing in some code above it, but for some reason, i get no table showing up on the site, it just says Username Character Name, but no data or table, which means my query must not be working correctly for some reason, anyone see anything wrong? i dont get it, because i have a query almost exactly like it

Code: Select all

"SELECT * FROM `guilds` WHERE `Tag` = '{$_SESSION['Guild']}'"
which works perfectly fine.
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

anyone please? if its possible, im almost done with this stupid section :lol:
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Try

Code: Select all

$result = mysql_query("SELECT * FROM `loginphp` WHERE `Guild` = '{$_SESSION['Guild']}'") or die(mysql_error());
and see if you get any rows from the DB
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

didnt work. i think that the query is working, its the part of the php that brings it up that isnt working, but i cant figure out where.
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

any other ideas anyone?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

try that query in phpMyAdmin and see if it's returning any rows
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

phpmyadmin works, i checked earlier and i dont know why i didnt say i did, but still, no display on my page, :(
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

try this:

Code: Select all

$result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error()); 
while($row=mysql_fetch_assoc($result)){
	echo '<pre>';
	print_r($row);
	echo '</pre>';
}die;
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

It worked, i know the query works, i tried it in phpmyadmin before you told me to, its the script, something in the code isnt showing up any results besdies username and character name, so i tried this instead.

Code: Select all

if($_GET['action'] == 'members')
{
echo "<font color=000000 span class='style3'><table><tr><td><b>Username</b></td><td><b>Character Name</b></td></tr>"; 
$result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error());
$row=mysql_fetch_assoc($result);
echo "<tr bgcolor='$strBGColor'><td>";
echo "<font color=000000 span class='style3'>" . $row['Uname'] . "</td><td>";
echo "<font color=000000 span class='style3'>" . $row['Cname1'] . "</td></tr>";
echo "</table>"; 
}
It shows up the first member the result from the query, but nothing else. so now i got it showing one member, theres 3, anyone see anything wrong with this code? because i dont...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Would you paste the output of my code? (in code tags please)
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

Code: Select all

Array
(
    [id] => 3
    [Uname] => Decus
    [Email] => decus_arillias@yahoo.com
    [Fname] => Michael
    [Lname] => Kessler
    [Pword] => xxxxxx
    [Kills] => 45654
    [Cname1] => Chimaira
    [Cname2] => 
    [Cname3] => 
    [Deaths] => 15
    [Drate] => 1
    [Paid] => 
    [Guild] => SLX
    [Family] => Williamsnapper
    [Kingdom] => Jade
)
Array
(
    [id] => 1
    [Uname] => Cyril
    [Email] => grant_kessler@neo.tamu.edu
    [Fname] => Grant
    [Lname] => Kessler
    [Pword] => xxxxxx
    [Kills] => 6464
    [Cname1] => Cyril
    [Cname2] => 
    [Cname3] => 
    [Deaths] => 1
    [Drate] => 100
    [Paid] => Yes
    [Guild] => SLX
    [Family] => 
    [Kingdom] => Jade
)
like i said it shows everything, just not the way i want it to. the last 2 codes ive used im making a table with the Uname and Cname1.
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 »

Read up on mysql_fetch_assoc() my friend -- the code Kieran wrote for you works, you just need to format the data.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

might have something to do with the fact that you're only selecting "Uname"..select * instead. And also use MySQL_fetch_assoc().
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

Code: Select all

if($_GET['action'] == 'members') 
{ 
echo "<font color=000000 span class='style3'><table><tr><td><b>Username</b></td><td><b>Character Name</b></td></tr>"; 
$result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error()); 
$row=mysql_fetch_assoc($result); 
echo "<tr bgcolor='$strBGColor'><td>"; 
echo "<font color=000000 span class='style3'>" . $row['Uname'] . "</td><td>"; 
echo "<font color=000000 span class='style3'>" . $row['Cname1'] . "</td></tr>"; 
echo "</table>"; 
}
that is the code about 5 posts up i said i used and only got one result from when i should get three.
i use the "*", not "Uname" and i use mysql_fetch_assoc

-_-
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

might be an html issue.... I've cleaned up your code a little, try this:

Code: Select all

if($_GET['action'] == 'members'){ 

	// start the table, make headers
	echo '<table class="style3"><tr><th>Username</th><th>Character Name</th></tr>';
	
	// fetch results from the DB
	$result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error()); 
	
	// print each row
	while($row=mysql_fetch_assoc($result)){
		echo '<tr style="background:'.$strBGColor.';">';
		echo '<td>'.$row['Uname'].'</td>';
		echo '<td>'.$row['Cname1'].'</td>'; 
		echo '</tr>';
	}
	
	// close the table
	echo '</table>'; 
}
You weren't looping through the rows, you were in theory only getting the first row.

The font tag is deprecated - never use it. You open 3 font tags and don't close them. There's no "span" attribute, and your span attribute has no value.

Also, if you want to be extra awesome, you should use <th> instead of <td> in the header.

You can get extra-extra awesome bonus points for separating your style completely from your markup with CSS.
Post Reply