php - Merge multiple database results into one -


i unsure call question. have been thinking lot it, , not think i've chosen covers adequately, best manage. forgive me if misleading or incorrect.

i creating small cms personal use, have stumbled upon trouble.

the information stored in mysql database, , table has 3 columns: cid, page , cont.

the cid identifier of piece of content. if page has multiple pieces of content, such main area of text , sub area of text, cid on these rows different, page same, seeing content on same page.

on index page of cms displaying different pages exist in database, links. user clicks link page on he'd want change content.

now, here issue:

when displaying data database, rows have same page, different cid is, logically, displayed separate links.

that sounded confusing. i'll differently:

what need that if result has same page result, these 2 merged 1 link, , not displayed 2 separate links.

this how database looks:

+------------+----------+-----------------------------------------+                                                                            | cid        | page     | cont                                    | +-----------------------------------------------------------------+   | page1-main | page1    | first page on website! |         | page2-main | page2    | second page!                |                                                                                                                                  | page2-sub  | page2    | sub-content!                    |                                                                   +------------+----------+-----------------------------------------+ 

as said, want have rows have same page merged 1 result in while loop, because happens separated 2 different results. loop , query:

$query = mysqli_query("select * content");  while($row = mysqli_fetch_array($query))   {    ?>      <a href="edit.php?p=<?php echo $row['page'];?>">link!</a>    <?php   } 

that will, of course, display 2 results, though have same page. unsure whether php have do, or in mysql query. bit unexperienced in sql, experienced in php.

i've been thinking ifs. like, storing every new result displayed in variable , comparing them, , if 1 has occurred before occurs again, not displayed, or something. don't know.

it wonderful if me out here.

> want have rows have same page > merged 1 result  

you can use group merge them:

$query = mysqli_query("select * content group page");


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -