Jump to content

SQL help


xyn

Recommended Posts

Hi,
This is very minor but it's quite irritating as it wont work. I'm trying to choose certain rows from my database as it is quicker to load pages and gather information, however my problem is i get blank spaces.

code:
[code=php:0]<?
$result = mysql_query("SELECT id,user,rank,rep FROM accounts ORDER BY 'id' ASC");
      while($data = mysql_fetch_row($result)){
     
      echo '<tr>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data["user"].'</font></td>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data["rank"].'</font></td>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data["rep"].'</font></td>
    <td width="25%" align="center" height="20">
    <font size="1" face="Verdana" color="#54A800">[ <a href="contact.php?id='.$data["id"].'">PM</a> ]</font></td>
  </tr>';
      }
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/14687-sql-help/
Share on other sites

Try this:
[code]
<?php
$result = mysql_query("SELECT id, user, rank, rep FROM accounts ORDER BY id ASC");
while ($data = mysql_fetch_row($result, MYSQL_NUM)) {
    echo '<tr>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data[1].'</font></td>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data[2].'</font></td>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data[3].'</font></td>
    <td width="25%" align="center" height="20">
    <font size="1" face="Verdana" color="#54A800">[ <a href="contact.php?id='.$data[0].'">PM</a> ]</font></td>
  </tr>';
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/14687-sql-help/#findComment-58582
Share on other sites

Oops, I'm stupid. I used mysql_fetch_row() instead of mysql_fetch_array(). I never use the first function, so I have no idea how it came into my head...oh, that's because it's what you were using. That was probably your problem.

Try this:

[code]
<?php
$result = mysql_query("SELECT id, user, rank, rep FROM accounts ORDER BY id ASC");
while ($data = mysql_fetch_array($result, MYSQL_NUM)) {
    echo '<tr>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data[1].'</font></td>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data[2].'</font></td>
    <td width="25%" align="center" height="20">
    <font face="Verdana" size="1" color="#54A800">'.$data[3].'</font></td>
    <td width="25%" align="center" height="20">
    <font size="1" face="Verdana" color="#54A800">[ <a href="contact.php?id='.$data[0].'">PM</a> ]</font></td>
  </tr>';
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/14687-sql-help/#findComment-58586
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.