Page 2 of 3

Posted: Tue Jan 02, 2007 1:29 am
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.

Posted: Wed Jan 03, 2007 5:08 pm
by ekosoftco
anyone please? if its possible, im almost done with this stupid section :lol:

Posted: Wed Jan 03, 2007 5:25 pm
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

Posted: Wed Jan 03, 2007 5:52 pm
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.

Posted: Thu Jan 04, 2007 10:07 pm
by ekosoftco
any other ideas anyone?

Posted: Thu Jan 04, 2007 11:02 pm
by Kieran Huggins
try that query in phpMyAdmin and see if it's returning any rows

Posted: Fri Jan 05, 2007 1:07 am
by ekosoftco
phpmyadmin works, i checked earlier and i dont know why i didnt say i did, but still, no display on my page, :(

Posted: Fri Jan 05, 2007 1:36 am
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;

Posted: Fri Jan 05, 2007 5:02 pm
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...

Posted: Fri Jan 05, 2007 6:10 pm
by Kieran Huggins
Would you paste the output of my code? (in code tags please)

Posted: Fri Jan 05, 2007 6:33 pm
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.

Posted: Fri Jan 05, 2007 8:32 pm
by aaronhall
Read up on mysql_fetch_assoc() my friend -- the code Kieran wrote for you works, you just need to format the data.

Posted: Fri Jan 05, 2007 8:43 pm
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().

Posted: Fri Jan 05, 2007 9:30 pm
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

-_-

Posted: Fri Jan 05, 2007 10:12 pm
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.