General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 27th, 2003, 01:10 PM
stc7outlaw stc7outlaw is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 stc7outlaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
pictures and numbers and text - bah

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 ahead 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:
<?php   

  

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


$num_rows = @mysql_num_rows($result);


  for ($id = 1; $id <= $num_rows; $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'];
    }
    

    

    


      }
 
?> 

Reply With Quote
  #2  
Old June 27th, 2003, 01:21 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
PHP Code:
for ($id 1$id <= $num_rows$id++ ) { 
should be
PHP Code:
for ($id 0$id <= $num_rows$id++ ) { 
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old June 27th, 2003, 01:49 PM
stc7outlaw stc7outlaw is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 stc7outlaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
that doesnt make it work.

Now the picture has an id of 0 and there is no picture with an id of 0 in my database because it starts with 1. The loops seems to stop too because no other pictures are put up.
Is there supposed to be another loop of some sort of is there another problem or somethin I overlooked?

Reply With Quote
  #4  
Old June 27th, 2003, 03:11 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Try this:

PHP Code:
<?php   

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

@
$conn mysql_connect('localhost',$user,$pass)
if(
$conn) { //Connected fine, continue code
    
$dbConn mysql_select_db($db,$conn);
    if(
$dbConn){ //Connected to db fine, continue code
        
$num_sql "SELECT * FROM $table"//Get the # entries
        
$num_res = @mysql_query($num_sql);
        
$num_entries = @mysql_num_rows($num_res);

        for (
$id 1$id <= $num_entries$id++ ){
                
//This should only return [b]1[/b] item, otherwise you have multiple entries with the same ID, which is bad.
            
$sql "SELECT * FROM $table WHERE id=$id";        

            
//You don't need the $sql,$conn since you already connected to the server up at the top.. removed it
            
$res = @mysql_query($sql)or die(mysql_error()); 
            
$result = @mysql_fetch_row($res); //$result becomes an array of the results from the query

            
if($result){ //If the result array isn't empty, assign $description and $section and print results
                
$description $result[description];
                
$section $result[section];
                
                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>';

            } 
//End if($result)
            
else { //No results returned
                
print 'No results returned.. or error';
            }
        } 
//End for loop
    
}//End if($dbConn)
    
else{ //Database error
        
print 'Database error, Could not connect to the database. Contact your system administrator.';
    } 
//End else - database error
//End if($conn)
else { //Couldn't connect to mysql.
    
die("Error connecting to mysql.\n");
}

?>

However you may have to change
PHP Code:
 $description $result[description];
$section $result[section]; 
to
PHP Code:
 $description $result[1];
$section $result[2]; 
or whatever position in the database table the description and section are... my example would be if the table is setup like this:

ID(position 0) Description(position 1) Section(position 2)

one problem that I saw with your code was you were trying to get the # of entries before you even connected to the mysql server or database... should have errored out there.. but try this.. see if it helps


Reply With Quote
  #5  
Old June 27th, 2003, 03:18 PM
stc7outlaw stc7outlaw is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 stc7outlaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Nicat, thanks,

There are no errors or any messages indicating failure, BUT.
Nothin happens. I also changed description and section as you indicated. When I typed the id number in the browser ex: &id=1 nothing happend either. Before I would see the picture and the text if i did this. Is something missing?
Please reply anyone,
thanks

Reply With Quote
  #6  
Old June 27th, 2003, 03:26 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
You aren't getting any error messages are you? so it is connecting to the database correctly and returning values?

Where you have the if($result){ //If the result array isn't empty...
make it look like this:
PHP Code:
if($result){ //If the result array isn't empty, assign $description and $section and print results
                
$numres count($result);
                for (
$temp 0$temp <= $numres$temp++){
                      print 
$result[$temp].' - position '.$temp.' <br><br>';
                }
                
$description $result[description];
                
$section $result[section]; 
that should echo the entries that are being returned

Last edited by nicat23 : June 27th, 2003 at 03:33 PM.

Reply With Quote
  #7  
Old June 27th, 2003, 03:41 PM
stc7outlaw stc7outlaw is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 stc7outlaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
nothin is being returned except the <BR><BR>.
Well, we may be able to trace what is goin on. Its not registering values so.......

Reply With Quote
  #8  
Old June 27th, 2003, 03:42 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
In place of:
PHP Code:
@mysql_select_db($db,$conn);
    
$sql "SELECT * FROM $table WHERE id=$id"
try
PHP Code:
 $temp_id $id -1;
    @
mysql_select_db($db,$conn);
    
$sql "SELECT * FROM $table WHERE id=$temp_id"

Reply With Quote
  #9  
Old June 27th, 2003, 03:48 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Ok do this.. add some lines to make the following code read accordingly

if($conn) { //Connected fine, continue code
add this--> echo "Connected fine to the db server.<Br>\n";

if($dbConn){ //Connected to db fine, continue code
add this--> echo "Connected fine to the database.<Br>\n";

$num_entries = @mysql_num_rows($num_res);
add this--> echo "num_entries = $numentries<br>\n";

for ($id = 1; $id <= $num_entries; $id++ ){
add this--> echo "The position in the for loop is $id<br>\n";

if($result){
add this--> echo "Result returned more than one value";

and change
print $result[$temp].' - position '.$temp.' <BR><Br>';

to

echo "$result[$temp] position - $temp <br><br>\n";

my print statement might be fubar I mainly use echo... let me know what the results are

Reply With Quote
  #10  
Old June 27th, 2003, 03:50 PM
stc7outlaw stc7outlaw is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 stc7outlaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i narrowed it down:

the for($id = 1; $id <= $num_rows; $id++ ){ statement isnt working because nothing returns inside those brackets. Note even print "hello world"; Anything higher than that is fair game for hello world. So it must mean that is not terminating, but I dont know how to figure out why its not.

Reply With Quote
  #11  
Old June 27th, 2003, 03:51 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Quote:
Originally posted by stc7outlaw
i narrowed it down:

the for($id = 1; $id <= $num_rows; $id++ ){ statement isnt working because nothing returns inside those brackets. Note even print "hello world"; Anything higher than that is fair game for hello world. So it must mean that is not terminating, but I dont know how to figure out why its not.


then
PHP Code:
 $num_entries = @mysql_num_rows($num_res); 
is probably returning nothing... add an echo statement after you get $num_entries to see what value is being stored in there.. we may need to re-write your sql statement

Reply With Quote
  #12  
Old June 27th, 2003, 04:07 PM
stc7outlaw stc7outlaw is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 stc7outlaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
did you edit part of your code because i was missing the whole part from num_entries and all of the num's?

Reply With Quote
  #13  
Old June 27th, 2003, 04:11 PM
stc7outlaw stc7outlaw is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 stc7outlaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
WHAT THE HELL?

This is weird. It printed all of the code that you would see if you opened a jpg in wordpad. Must have printed all the text from the whole database in kinda postbinary. I know for a fact mine are all set up fine as blobs becasue they were working eariler. You seen anthing like it? I'll give you the link if you want it.

Reply With Quote