Jump to content


Photo

SQL help


  • Please log in to reply
9 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 15 July 2006 - 05:23 PM

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:
<?
$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>';
      }
?>


#2 koolaidman52

koolaidman52
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 15 July 2006 - 05:26 PM

methinks $data["rep"] needs to be  {$data["rep"]}

also are you afraid of escaping quotation marks or something? you could do that whole thing without periods
Btcartoons.com --  coded entirely in Mom's basement.

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 15 July 2006 - 05:26 PM

Nope i got errors

#4 koolaidman52

koolaidman52
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 15 July 2006 - 05:28 PM

what errors?

are you logged onto the DB? (using mysql_connect and mysql_select_db)
Btcartoons.com --  coded entirely in Mom's basement.

#5 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 05:29 PM

Try this:
<?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>';
}
?>

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#6 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 05:32 PM

Try miiiiiiiiiine. :)

Dude, you don't use { } when dealing with single quotes.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#7 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 15 July 2006 - 05:32 PM

I have tried yours :P

i got this:
Warning: Wrong parameter count for mysql_fetch_row() in /home/zroxxco/public_html/Zone/Members.php on line 52

#8 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 05:38 PM

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:

<?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>';
}
?>

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#9 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 15 July 2006 - 05:41 PM

Thanks pix. btw when i tried array it stayted the same
although its probably becuase i done this:
'.$data['id'][0].' rofl, but works now :]
thanks

#10 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 05:44 PM

Lol, that might cause a problem.

Glad you got it worked out.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users