Jump to content


Photo

need some help with a kinda complicated code (maybe)


  • Please log in to reply
14 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 18 June 2006 - 10:32 PM

<?php

    include "../inc/connect.php";
    $query = "SELECT fullsize FROM table1,table2 WHERE id='%'";
    $result = mysql_query( $query );
    
    if ( !$result ) {
           die($query.'<br />'.mysql_error());
    }
                        
    // Build Table
    while( $row = mysql_fetch_assoc( $result ) ) {
    
                        
    echo "<br /><br />$row[fullsize]";
    
    
    }
             
         
?>

thats the code, what i want it to do is echo the fullsize of the image to the page when the url is view.php?id=1 or id=2 or id=3, etc...

the data thats in the fullsize field is this:
<img border='0' src='http://mysite.com/image.jpg'>

can anyone help me? please i been trying to figure this out for a long time kthanks.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 18 June 2006 - 10:33 PM

Why are you querying 2 tables? What is the table structure?
How are the images stored?
~ D Kuang

#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 18 June 2006 - 10:41 PM

im querying two tables because they both contain fullsize images i need to echo on that page when the url is view.php?id=1, 2, etc...

the two tables have the same exact field names too. they just have different data in the fields. table1 contains id's 1-17 and table2 contains id's 18-49.

#4 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 18 June 2006 - 11:19 PM

:(

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 18 June 2006 - 11:22 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]table1 contains id's 1-17 and table2 contains id's 18-49.[/quote]
Then you need to rethink your database design. Look into database normalization techniques.

#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 18 June 2006 - 11:27 PM

[!--quoteo(post=385463:date=Jun 18 2006, 07:22 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 18 2006, 07:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Then you need to rethink your database design. Look into database normalization techniques.
[/quote]

what do u mean????

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 June 2006 - 11:33 PM

[!--quoteo(post=385465:date=Jun 18 2006, 07:27 PM:name=newb)--][div class=\'quotetop\']QUOTE(newb @ Jun 18 2006, 07:27 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
what do u mean????
[/quote]
Let's start slowly. Why do you have two database tables that contain the same fields for what appears to be the same type of data? Is the content of your 'full image' database field the name of the image, the image itself (as a blob field), or the html code you posted?

Legend has it that reading the manual never killed anyone.
My site

#8 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 18 June 2006 - 11:35 PM

Why do you have two tables containing the same data? There is very rarely a good reason for this.

As I said.... Look into database normalization techniques.

#9 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 18 June 2006 - 11:40 PM

the two tables dont contain the same data, i never said that. i just said that the two tables contain the same field names. the data inside the fields are different though.

Is the content of your 'full image' database field the name of the image, the image itself (as a blob field), or the html code you posted?


<img border='0' src='http://mysite.com/image.jpg'>

that html code is in the 'fullsize' field of table2 in the 'id 18' field. i want that to echo when the browser's url is view.php?id=18

i hope i cleared up a bit.

#10 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 19 June 2006 - 12:35 AM

can I see what data is in table 1 where id = 15 please?

#11 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 June 2006 - 01:41 AM

[!--quoteo(post=385471:date=Jun 18 2006, 04:40 PM:name=newb)--][div class=\'quotetop\']QUOTE(newb @ Jun 18 2006, 04:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
the two tables dont contain the same data, i never said that. i just said that the two tables contain the same field names. the data inside the fields are different though.
<img border='0' src='http://mysite.com/image.jpg'>

that html code is in the 'fullsize' field of table2 in the 'id 18' field. i want that to echo when the browser's url is view.php?id=18

i hope i cleared up a bit.
[/quote]
I think that what he means is: "why do you have different tables when you could put them all in the same"?

Like:

table1:
id, image [ids 1-15]

table2:
id. image [ids-16-26]

There is no point in doing this.
~ D Kuang

#12 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 19 June 2006 - 01:52 AM

[quote]
can I see what data is in table 1 where id = 15 please?
[/quote]

yeah sure.

[img src=\"http://img230.imageshack.us/img230/3748/data1ut.jpg\" border=\"0\" alt=\"IPB Image\" /]

there's what it look like.

[!--quoteo(post=385487:date=Jun 18 2006, 09:41 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 18 2006, 09:41 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think that what he means is: "why do you have different tables when you could put them all in the same"?

Like:

table1:
id, image [ids 1-15]

table2:
id. image [ids-16-26]

There is no point in doing this.
[/quote]

itll help me organize them better. some pictures belong in certain sections on the site.

#13 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 June 2006 - 01:56 AM

1st: Using VARCHAR for id's may be cumbersome. Using INT & AUTO_INCREMENT & PRIMARY KEY for id's is a good idea.

2nd: Why are you storing HTML code in "thumb" and "fullsize"? Store just the image name - unless you want to change the <img> attributes for each image.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]itll help me organize them better. some pictures belong in certain sections on the site.[/quote]

3rd: Not a good practice, normalize your database. You may add a new field called category if you need one.
~ D Kuang

#14 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 19 June 2006 - 02:00 AM

oh ok, will merge/normalize the tables then since they have the same fields. is there a way i can do this quickly since they all have the same fields so then i dont have to re-enter all the data again?

#15 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 19 June 2006 - 02:59 AM

nevermind, i found the SQL query on how to merge the two tables into one. it's this:

CREATE TABLE `newtable` (
  `id` varchar(32) NOT NULL default '',
  `title` varchar(32) NOT NULL default '',
  `artist` varchar(32) NOT NULL default '',
  `size` varchar(32) NOT NULL default '',
  `thumb` text NOT NULL,
  `fullsize` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `newtable`
Select * from table1
UNION
Select * from table2;

thanks for the help guys.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users