Jump to content


Photo

MySQL Query Problems


  • Please log in to reply
1 reply to this topic

#1 xCypherx

xCypherx
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 17 October 2005 - 11:15 PM

hmm for some reason my script will only show 1 field when it should show 2 both with images see if you can see whats wrong with my script :( i know its messy, but im quite new...

<?php
$username="user";
$password="pass";
$database="db1";
 
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) OR die( "Unable to select database");
$query="SELECT * FROM ibf_members WHERE (`mgroup`='6' OR `mgroup_others`='6') ORDER BY `joined`";
$result=mysql_query($query);
 
$num=mysql_numrows($result);
 
mysql_close();
 
echo "<b><center>Roster</center></b><br>";
 
$i=0;
while ($i < $num) {
echo($num);
 
$name=mysql_result($result,$i,"name");
$email=mysql_result($result,$i,"email");
$id=mysql_result($result,$i,"id");
 
 
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) OR die( "Unable to select database");
$sql="SELECT * FROM ibf_pfields_content WHERE (`member_id`='$id')";
$result2=mysql_query($sql);
$num=mysql_numrows($result2);
 
mysql_close();
 
 
$image=mysql_result($result2,$i,"field_2");
?>
 
<font face="Arial, Helvetica, sans-serif"><a href="index.php?showuser=<? echo $id; ?>"><? echo $name; ?></a><img src=/style_flags/<? echo $image; ?>></font><br>
 
<?php
$i++;
}
 
 
?> 


#2 khuti

khuti
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 October 2005 - 06:10 AM

hi, duno if this seems easier for u, but i find it easier to do things like this..

$db = mysql_connect("localhost", "user", "pass");
mysql_select_db("database_name", $db);

$result = mysql_query("SELECT * FROM table_name ORDER BY sumink_like_id_is_always_good ASC", $db);

while($row=mysql_fetch_array($result))
{

echo("name ur field:" . $row['field_name']);
echo("if more than one thing u can do it like this");
echo("1: " . $row['field_name'] . " 2: " . $row['2nd_field'] . ");

}

mysql_close();

---

hope this helps..

khuti




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users