ayok Posted June 10, 2008 Share Posted June 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
ayok Posted June 10, 2008 Author Share Posted June 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
ayok Posted June 10, 2008 Author Share Posted June 10, 2008 anybody, please? Quote Link to comment Share on other sites More sharing options...
ayok Posted June 11, 2008 Author Share Posted June 11, 2008 Is this impossible? Quote Link to comment Share on other sites More sharing options...
zenag Posted June 11, 2008 Share Posted June 11, 2008 <? $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; }; ?> Quote Link to comment Share on other sites More sharing options...
ayok Posted June 11, 2008 Author Share Posted June 11, 2008 Thank zenag, Is it not possible to generate the table dynamicaly? ayok Quote Link to comment Share on other sites More sharing options...
fenway Posted June 11, 2008 Share Posted June 11, 2008 You can use a JOIN to get the categories... but the output is php-based. Quote Link to comment Share on other sites More sharing options...
luca200 Posted June 11, 2008 Share Posted June 11, 2008 Is this impossible? The matter is the "thing" you posted is NOT a table, while a query result is. Quote Link to comment Share on other sites More sharing options...
ayok Posted June 11, 2008 Author Share Posted June 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
ayok Posted June 11, 2008 Author Share Posted June 11, 2008 Is this impossible? The matter is the "thing" you posted is NOT a table, while a query result is. Actually i'm trying to make a list, which can be updated through a database. Quote Link to comment Share on other sites More sharing options...
ayok Posted June 11, 2008 Author Share Posted June 11, 2008 It's solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.