?
Solved

my sql question, should be easy

Posted on 2003-03-10
3
Medium Priority
?
188 Views
Last Modified: 2006-11-17
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
Comment
Question by:hAhA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Expert Comment

by:Jonza
ID: 8108930
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
 
LVL 15

Accepted Solution

by:
VGR earned 200 total points
ID: 8109307
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
 

Author Comment

by:hAhA
ID: 8115182
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question