mikebyrne Posted February 5, 2008 Share Posted February 5, 2008 I want to put my sales figures into the table below. The table name is Sales which is linked by using require_once('adminconnect.php'); $tbl2 = 'sales'; The fields in the table are Date, Total Orders & Revenue. What would the php be to place this into a table? <form> <!-- data title start --> <div id="containerBg2"> <div class="padTop2"><!-- --></div> <div class="clr"><!-- --></div> <div class="titleBox"> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td width="33"> </td> <td width="87"><a href="#">date</a></td> <td width="43" align="right"><a href="#">orders</a></td> <td width="118" align="right"><a href="#">revenue</a></td> <td width="569"> </td> </tr> </table> </div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data title finish --> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data btm finish --> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="container"> <div id="line"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="padTop16"><!-- --></div> <div class="clr"><!-- --></div> <!-- btm finish --> </form> Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/ Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Query the DB, do a SELECT *, use a while loop and mysql_fetch_array, then echo each row like echo $row[0]; echo $row[1]; etc Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459120 Share on other sites More sharing options...
mikebyrne Posted February 5, 2008 Author Share Posted February 5, 2008 Like <?php include('adminconnect.php'); $sql = mysql_query("SELECT Date, Total Orders, Revenue FROM sales "); while( $row = mysql_fetch_array($sql) ) { ?> <tr align="left"> <td width="87" align="center"><?php echo $row['Date'];?></td> <td width="43" align="Left"><?php echo $row['Total Orders'];?></td> <td width="118" align="center"><?php echo $row['Revenue'];?></td> </tr> <? } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459131 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 You tell me Use <?php on that second tag though instead of just <? Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459132 Share on other sites More sharing options...
mikebyrne Posted February 5, 2008 Author Share Posted February 5, 2008 getting the error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Admin_files\Sales.php on line 152 line 152 refers above the first ?> Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459138 Share on other sites More sharing options...
revraz Posted February 5, 2008 Share Posted February 5, 2008 Your query isn't valid. Just do a SELECT * You can also add a mysql_error() after your query to find the error. Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459140 Share on other sites More sharing options...
mikebyrne Posted February 5, 2008 Author Share Posted February 5, 2008 How do i get the figures in line with my headings and also appear row by row as opposed to next to each other? Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459198 Share on other sites More sharing options...
revraz Posted February 6, 2008 Share Posted February 6, 2008 TR is for a new Row TD is for data in a Row Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459431 Share on other sites More sharing options...
mikebyrne Posted February 6, 2008 Author Share Posted February 6, 2008 yeah i know that my code is <tr align="left"> <td width="87" align="center"><?php echo $row['Date'];?></td> <td width="43" align="Left"><?php echo $row['Total Orders'];?></td> <td width="118" align="center"><?php echo $row['Revenue'];?></td> </tr> It goes through the loop but puts the results next to each other as opposed to on new row Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459600 Share on other sites More sharing options...
Aureole Posted February 6, 2008 Share Posted February 6, 2008 EDIT: Nevermind, I didn't read your post properly... Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459612 Share on other sites More sharing options...
mikebyrne Posted February 6, 2008 Author Share Posted February 6, 2008 Still cant get it to post the results underneath each other!! Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459632 Share on other sites More sharing options...
revraz Posted February 6, 2008 Share Posted February 6, 2008 Post a screenshot of what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459769 Share on other sites More sharing options...
mikebyrne Posted February 6, 2008 Author Share Posted February 6, 2008 How do i insert a screenshot between the image tags??? Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-459916 Share on other sites More sharing options...
mikebyrne Posted February 6, 2008 Author Share Posted February 6, 2008 The results are printing out like: date orders revenue 2008-02-05 50 13000 2008-02-06 56 17000 But id like them to be something like date orders revenue 2008-02-05 50 13000 2008-02-06 56 17000 Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-460000 Share on other sites More sharing options...
Aureole Posted February 8, 2008 Share Posted February 8, 2008 Use a table. Quote Link to comment https://forums.phpfreaks.com/topic/89610-placing-sales-figures-into-table/#findComment-461650 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.