Jump to content

[SOLVED] MySql Query question


ayok

Recommended Posts

Hi,

 

I have "portfolio" table, and "catPort" table with these fields:

 

portfolio:

id | category | image

------------------------

1  | 1          | img1.jpg

2  | 1          | img2.jpg

3  | 2          | img3.jpg

4  | 2          | img4.jpg

5  | 3          | img5.jpg

6  | 3          | img6.jpg

 

catPort:

catId | catName

----------------

1      | Website

2      | Print

3      | Illustration

 

The question is, what should be the mysql query to get this table?

 

Website

img1.jpg

img2.jpg

 

Print

img3.jpg

img4.jpg

 

Illustration

img5.jpg

img6.jpg

 

Thank you,

 

ayok

Link to comment
Share on other sites

I've tried this:

<?php
$gallery = mysql_query("select portfolio.*,catPort.* from portfolio,catPort where portfolio.category = catPort.catId group by category");

while($gal = mysql_fetch_array($gallery)){
echo $gal["catName"]."<br>";
echo $gal['image']."<br>";
}?>

 

But only get this result:

Website

img1.jpg

 

Print

img3.jpg

 

Illustration

img5.jpg

 

Link to comment
Share on other sites

<?
$con=mysql_connect("localhost","root","");
mysql_select_db("login",$con);
$j=0;
for($i=0;$i<=4;$i++)
{
$z= $j+2;
//echo "select * from user limit($j,$z)";
$sql=mysql_query("select * from user limit $j,$z");
while($row=mysql_fetch_array($sql))
{
?><table><tr><td>heading1</td></tr><tr><td>
<? if($z==2){ echo $row["nickname"];}?></td></tr></table>

<table><tr><td>heading2</td></tr><tr><td>
<? if($z==4){ echo $row["nickname"];}?></td></tr></table>

<table><tr><td>
<? if($z==2){ echo $row["nickname"];}?></td></tr></table>

<?
}
$j=$j+2;
};

?>



Link to comment
Share on other sites

Hi,

 

Here is my try, and it's closed with what i've been expecting. Would someone help me with it?

 

<?php

$category = mysql_query("select * from catPort order by catID") or die(mysql_error());

while($cat = mysql_fetch_array($category)){
$gallery = mysql_query("select portfolio.*,catPort.* from portfolio,catPort where portfolio.category = '$cat[catId]'") or die(mysql_error());
echo $cat["catName"]."<br>";
while($gal = mysql_fetch_array($gallery)){
	echo $gal['image']."<br>";
}
}?>

 

This is what I've got:

Website

img1.jpg

img1.jpg

img1.jpg

img2.jpg

img2.jpg

img2.jpg

 

Print

img3.jpg

img3.jpg

img3.jpg

img4.jpg

img4.jpg

img4.jpg

 

Illustration

img5.jpg

img5.jpg

img5.jpg

img6.jpg

img6.jpg

img6.jpg

 

I guess because I make my sql query in the while loop statement. But i don't know how to make those appear only once.

Could anybody help me out?

 

ayok

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.