master82 Posted July 6, 2006 Share Posted July 6, 2006 In my database I have the table [b]market[/b] that contains the fields:[b]id[/b](a unique field for the table)[b]sellerid[/b](contains the selling members id)[b]qty[/b](Number being sold)[b]price[/b](how much its on the market for)I need two things,Firstly, I need to create the php script to show the listand secondly, next to each row in the list a hyperlink to seller.php?id=?? (where ?? is the id of the row in the database)Can it be done? Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/ Share on other sites More sharing options...
shocker-z Posted July 6, 2006 Share Posted July 6, 2006 This should work mate, you also need to make the connection to database but i'm taking it that you have already done the connection part.<?php$result=mysql_query("SELECT * FROM market");while ($row=mysql_fetch_array($result)) { echo "$row[sellerid], $row[qty], $row[price] <a href='seller.php?id=$row[id]>the link</a><Br>";}?>Just basic, you can add formatting yourself :)RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/#findComment-53975 Share on other sites More sharing options...
wildteen88 Posted July 6, 2006 Share Posted July 6, 2006 Thats pretty simple:[code=php:0]// connect to db here$sql = 'SELECT * FROM market';$result = mysql_query($sql);echo '<table border="0" cellpadding="0" cellspacing="0">';echo '<tr><th>id</th>';echo '<th>Seller id</th>';echo '<th>Price</th>';echo '<th>Qty</th>';while ($row = mysql_fetch_row($result)){ echo '<tr><td>' . $row['id'] . '</td>'; echo '<td><a href="seller.php?id=' . $row['sellerid'] . '">Seller id</a></td>'; echo '<td>' . $row['price'] . '</td>'; echo '<td>' . $row['qty'] . '</td></tr>';}echo '</table>';[/code]Thats the basic code. Its untested but it should work. Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/#findComment-53979 Share on other sites More sharing options...
Orio Posted July 6, 2006 Share Posted July 6, 2006 [code]<?php//connect to db here$query="SELECT * FROM `market`";$result=mysql_query($query);while($row=mysql_fetch_array){echo("------------------<br><strong>ID: </strong>".$row['id']."<br><strong>Seller-ID: </strong>".$row['sellerid']."<br><strong>Quantity: </strong>".$row['qty']."<br><strong>Price: </strong>".$row['price']."<br><strong>Link: <a href=\"seller.php?id=".$row['id']."\">Click here</a><br><br>");};?>[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/#findComment-53980 Share on other sites More sharing options...
master82 Posted July 6, 2006 Author Share Posted July 6, 2006 Work great guys - thank you.Just one other small thing I would like to know,I want to sort the list by price, how do I go about that?I've got as far as this line, adding order by...[b]$result=mysql_query("SELECT * FROM mmarket ORDER BY price");[/b]...but how do I specify it to be ordered ascending or decending?Once again guys - thanx ;) Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/#findComment-54021 Share on other sites More sharing options...
master82 Posted July 6, 2006 Author Share Posted July 6, 2006 Nevermind - it does it the way I want it automatically lol Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/#findComment-54024 Share on other sites More sharing options...
cmgmyr Posted July 6, 2006 Share Posted July 6, 2006 Ascending[code]$result=mysql_query("SELECT * FROM mmarket ORDER BY price ASC");[/code]Descending[code]$result=mysql_query("SELECT * FROM mmarket ORDER BY price DESC");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/#findComment-54025 Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 but just so you know, it would be like so:select * from mmarket order by price ascselect * from mmarket order by price desc Quote Link to comment https://forums.phpfreaks.com/topic/13863-creating-a-list-from-database/#findComment-54026 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.