Jump to content

tables select


corillo181

Recommended Posts

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

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)

???????
Link to comment
Share on other sites

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

[code]SELECT * FROM `table` WHERE condition[/code]

And that will grab all of the columns. Sorry if I didn't answer your question.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.