• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

my sql question, should be easy

hey I have another question, I cannot figure out what's wrong with my php, here is the php, and the link where I am trying to use it:
--------
<table width="100%" border="1">
<tr><th>ID<th>Image<th>Name<th>Base HP<th>Base MP<th>Active
<?
include 'db.php';
function x_dir($param)
 {
    $dir   = opendir($param);
    $files = array();
    while ($ff=readdir($dir))
          {
          if ($ff!=".." && $ff!=".")
             {
             $files[count($files)]=$ff;
             }
          }
   return $files;
 }
$result = x_dir("enem/");

for ($i=0;$i<count($result);$i++) {
     echo '<tr><th>'.$i.'<th width="50"><img src="enem/'.$result[$i].'"><th>';
          $products=array();
          mysql_select_db($database_name,$connection) or die ("bad select DB ".mysql_error());
          $query="select * from usersenem;";
          $result=mysql_query($query,$connection) or die ("bad query $query. ".mysql_error());
          while ($res=mysql_fetch_array($result)) {
            $enem_name=$res["enem_name"];
            $enem_hp=$res["enem_hp"];
            $enem_mp=$res["enem_mp"];
            $ID=$res["id"];
          }
          echo $enem_name.'<th>'.$enem_hp.'<th>'.$enem_mp;
}
?>
</table>

--------
http://phpwarz.cscomps.com/admin.php

thanks in advance, im still trying to figure out these mysql tables : \
0
hAhA
Asked:
hAhA
1 Solution
 
JonzaCommented:
what is the problem you are having?

try using
this
while ($res=mysql_fetch_assoc($result)) {


instead of this
while ($res=mysql_fetch_array($result)) {

thjen you can access the records the way you are trying
0
 
VGRCommented:
COMPLETELY WRONG
stick with
while ($res=mysql_fetch_array($result)) {
           $enem_name=$res["enem_name"];
           $enem_hp=$res["enem_hp"];
           $enem_mp=$res["enem_mp"];
           $ID=$res["id"];
}
         

it's the proper way to do it.

To show you where is your problem, I'll simplify your code and let you see :D

$result = x_dir("enem/");

for ($i=0;$i<count($result);$i++) {
  // correctly written DB stuff
  $result=mysql_query($query,$connection) [...];
  while ($res=mysql_fetch_array($result)) {
    // correctly written DB stuff        
  }
}

Do you see the problem ? :D :D

You have TWO $results variables overwriting themselves 8-))

Just rename the second one in $result2 and it'll work 8-)

**** modify code below ***
$result2=mysql_query($query,$connection) or die ("bad query $query. ".mysql_error());
while ($res=mysql_fetch_array($result2)) {
**** end of modify code ***
0
 
hAhAAuthor Commented:
thanks, both of you, but I figured out what the hell I was doing and got it to work before you responded : )
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now