954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

not workin??! mysql while loop

<?php

mysql_connect("localhost", "Master", "pword");
mysql_select_db("db");

	$official2 = mysql_query("SELECT * FROM Contribute WHERE stack LIKE '%comic%' ORDER BY points DESC")or die (mysql_error());
	while($row = mysql_fetch_array($official2)) {
	$officaluser = $row['username'];
	
	$officalpoints = $row['points'];
	
	
	
	echo "<table><tr><td align='center'><font face='Arial' size='3px' color='#D99C29'><strong><a href='ustack.php?search=$officialuser' style='text-decoration: none'>$officialuser</a></strong></font></td><td align='center'><font face='Arial' size='3px' color='#FFFFFF'><strong>$officialpoints</strong></font></td></tr></table>";

}
?>


the page is coming up blank??!?

MDanz
Junior Poster
152 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Well, if there are no results, nothing will be displayed.

colweb
Posting Whiz
318 posts since Nov 2007
Reputation Points: 34
Solved Threads: 52
 

try as given below with @ sign

@mysql_connect("localhost", "Master", "pword");
@mysql_select_db("db"); 	
$official2 = @mysql_query("SELECT * FROM Contribute WHERE stack LIKE '%comic%' ORDER BY points DESC")OR die (mysql_error());
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 
<?php

mysql_connect("localhost", "Master", "pword");
mysql_select_db("db");

	$official2 = mysql_query("SELECT * FROM Contribute WHERE stack LIKE '%comic%' ORDER BY points DESC")or die (mysql_error());
	while($row = mysql_fetch_array($official2)) {
	$officaluser = $row['username'];
	
	$officalpoints = $row['points'];
	
	
	
	echo "<table><tr><td align='center'><font face='Arial' size='3px' color='#D99C29'><strong><a href='ustack.php?search=$officialuser' style='text-decoration: none'>$officialuser</a></strong></font></td><td align='center'><font face='Arial' size='3px' color='#FFFFFF'><strong>$officialpoints</strong></font></td></tr></table>";

}
?>

the page is coming up blank??!?

After a second look at your code, there are a few thing to change. Fist of all, you have the complete table inside the while loop. That means every time the loop executes, a new table is created. So before the while loop you need

echo "<table>";


and after

echo "</table>";


Inside the wile the echo might work if written like this:

echo "<tr><td align='centter'>
    <font face='Arial' size='3px' color='#D99C29'>
    <strong><a href='ustack.php?search=".$officaluser."' style='text-decoration:none'>".$officaluser."</a></strong></font>
</td>
<td align='center'>
    <font face='Arial' size='3px' color='#FFFFFF'>
    <strong>".$officalpoints."</strong></font>
</td>
</tr>

If you don't notice the change, I did place ". and ." around the variables.

colweb
Posting Whiz
318 posts since Nov 2007
Reputation Points: 34
Solved Threads: 52
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You