Jump to content


Photo

tables select


  • Please log in to reply
5 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 22 May 2006 - 03:30 AM

SELECT
    photo.*,          # Field list 
    albums.*
FROM
    tra_photo photo,
    tra_albums albums
WHERE
    photo.album_id = album.album_id

i always only pulled 2 table results from 2 tables.. but what if i wanted more then 2 coloums result how would i got about it?

photo.photoname ,
albums(name,descibtion)

???????

#2 chawezul

chawezul
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationSomewhere, for sure

Posted 22 May 2006 - 04:52 AM

It's kind of hard to understand what you're asking, plus you didn't show us how this query is applied to your code so it's harder to understand what you're trying to do with the result. But if you want to grab more columns (and assuming you don't have a million) you can simply use

SELECT * FROM `table` WHERE condition

And that will grab all of the columns. Sorry if I didn't answer your question.

#3 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 22 May 2006 - 04:55 AM

sorry.. what i'm trying to do is selecting from 2 tables.. more than 2 fields with out using * ..

kind of like this

$query=mysql_query("SELECT tra_photo.photoname, tra_albums.name FROM tra_photo, tra_albums WHERE tra_photo.album_id=tra_albums.album_id");

but more than 2 fields

#4 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 22 May 2006 - 05:13 AM

"SELECT row1_table1, row3_table2, row6table_1 FROM table_1, table_2"
Everything you want to know is here.

#5 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 22 May 2006 - 05:39 AM

yeah i'm kind growing in this.. now this my new and almost last question :D

i still got one more after this one..

i'm taking it step by step becuase i want to give a few try and make sure i know what i'm doing before i ask something else.. if i ask everything at once ppl are going to post a whole script and that wouldn't be learning..

now this is many new question..

ok i got the albums and the describtion and the name of the picture the belong to the album to display..

the problem: every time a new picture is added it display all the information.. the album name and the album describtion..

what i want to do: just add the name of the ne wpicture to dis play in the album it belongs to..

this is how it looks:

album name: clubsparty
ablum desc: pictures about clubs and party
photo names: 920608809.jpg

if add a ne wpicture just adds another row
album name: clubsparty
ablum desc: pictures about clubs and party
photo names: new picture.jpg

how i want it to look..

album name: dablock
ablum desc: Rep your block or whatever you want this is for the hood
photo names: 27490662.jpg, new picture name,newpicture name, new picture name..



this code doesn't do that.. help me fix that thanx..
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php
session_start();
include_once'includes/db.php';

$query=mysql_query("SELECT tra_albums.name,tra_albums.descrive,tra_photo.fotoname FROM tra_albums,tra_photo WHERE tra_albums.album_id=tra_photo.album_id LIMIT 3");

while($array=mysql_fetch_array($query)){

$name=$array['name'];
$piname=$array['descrive'];
$pname=$array['fotoname'];

echo "album name: ".$name."<BR>"."ablum desc: ".$piname."<BR>"."photo names: ".$pname."<BR>";
}
?>[/quote]

#6 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 22 May 2006 - 06:34 AM

well i found a way.. but if ther eis any other faster way around it.. i'll be happy to know..
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php
session_start();
include_once 'db.php';

$query=mysql_query("SELECT album_id,tra_albums.name,tra_albums.descrive FROM tra_albums ");

while($array=mysql_fetch_array($query)){

$name=$array['name'];
$piname=$array['descrive'];
$id=$array['album_id'];

$query2=mysql_query("SELECT fotoname FROM tra_photo where album_id='$id'");
$fetch=mysql_fetch_array($query2);
$potoname=$fetch['fotoname'];

echo "album name: ".$name."<BR>"."ablum desc: ".$piname."<BR>";
echo " photoname:";
$query2=mysql_query("SELECT fotoname FROM tra_photo where album_id='$id'");
while($fetch=mysql_fetch_array($query2)){
$potoname=$fetch['fotoname'];

echo $potoname;
}
echo "<br>";
}
?>
[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users