pictures and text placement

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
stc7outlaw
Forum Newbie
Posts: 21
Joined: Mon Jun 09, 2003 9:36 pm

pictures and text placement

Post by stc7outlaw »

I seem to be having a problem. What I am doing it pulling pictures, their description, and their section off of the database. I got it to work, but in the loop I usually have to insert a number for num_rows and it seems that the description and section text are matched up with 1 picture after of where they should be.
EX: picture 1 - no text
picture 2 -picture 1's text
picture 3 -picture 2's text.
I have been racking my brain on this and cant seem to match up the text with the picture. Is my loop wrong, or is my table id screwed up? Please help. CODE:

Code: Select all

extract($_GET);
extract($_REQUEST);
$user = "oprods";
$pass = "breakin";
$db  = "pictures";
$table = $_REQUEST['table'];

   $num_rows = @mysql_num_rows($result);
    echo $num_rows;


  for ($id = 1; $id <= 3; $id++ ) {




     print '<TR>';
     print '<TD width=33%><img src=getdata.php?id='.$id.'&table='.$table.' width=404 height=295></TD>';
     print '<TD width=33%>'.$description.'</TD>';
     print '<TD width=33%>'.$section.'</TD>';
     print '</TR>';


    $conn = @mysql_connect('localhost',$user,$pass) or die(mysql_error());
    if(!is_resource($conn)) {
       die("Error connecting to mysql.\n");
    }

    @mysql_select_db($db,$conn);
    $sql = "SELECT * FROM $table WHERE id=$id";
    $result = @mysql_query($sql,$conn)or die(mysql_error());
 
      while ($newarray = @mysql_fetch_array($result, MYSQL_BOTH)) {
          $description = $newarray['description'];
           $section = $newarray['section'];
    }
    

    

      


      }


?>
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

try this:

change your for loop to start at "0":

Code: Select all

for ($id = 0; $id <= 3; $id++ ) { 




     print '<TR>'; 
     print '<TD width=33%><img src=getdata.php?id='.$id.'&table='.$table.' width=404 height=295></TD>'; 
     print '<TD width=33%>'.$description.'</TD>'; 
     print '<TD width=33%>'.$section.'</TD>'; 
     print '</TR>'; 


    $conn = @mysql_connect('localhost',$user,$pass) or die(mysql_error()); 
    if(!is_resource($conn)) { 
       die("Error connecting to mysql.\n"); 
    }
Post Reply