Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 107,708 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,134 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



How to place items from DB into table

 
Reply to this topicStart new topic

How to place items from DB into table

King8654
post 16 Jul, 2008 - 11:30 AM
Post #1


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 89


My Contributions


Hey ,

back again with a prob. freshexams has a request feature, where users can search requests, and fill request based on if they find anything. But its very annoying to not have a table on the main page listing the requested exams, make finding requests ackward. I know how to make the table with php, but not sure how to call/query the info into the table.

the main table is requests, and the rows are

request_id sub_id sub_sub_id school class description is_filled uploader_id upload_date

request id is its upload id, starting at 1 from the first request.
subid is its respective main category(math, science, etc.)
subsubid is its subcategory underneath a main subject
school, class, description obv
is filled either 0/1
upload id and upload date obv

i just want a table like my search spits out, with the request id, school, class in the table descending. Today i realized there were about 10 requests, but i didnt know until i checked the db b/c the way it is now you only know if people requested an exam if you search for that specific one. Please help

This is the code I have to show a users uploaded exams in their account, only difference is diff table/rows
CODE

<?
    $q="select * from `topics` where `uploader_id`='".$_SESSION['login_id']."'";
    $r=mysql_query($q);
?>

<table width="500" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000033">
  <tr align="center" valign="middle">
    <td width="180" height="30" bgcolor="#CDE4FE"><strong><font face="Georgia,Times New Roman,serif">Subject</font></strong></td>
    <td width="160" height="30" bgcolor="#CDE4FE"><strong><font face="Georgia,Times New Roman,serif">File
      Name</font></strong></td>
    <td width="160" height="30" bgcolor="#CDE4FE"><strong><font face="Georgia,Times New Roman,serif">Uploaded
      Time</font></strong></td>
  </tr>
  <?
    while($row=@mysql_fetch_array($r,MYSQL_BOTH))
    {
        $sub_id=$row[1];
        $q2="select * from `subjects` where `id`=".$sub_id;
        $r2=mysql_query($q2);
        $row2=@mysql_fetch_array($r2);
        $sub_name=$row2[1];
        $subject=explode("_",$row2[1]);
?>
  <tr align="center" valign="middle">
    <td width="150" height="30"> <font color="#000033" size="2" face="Georgia,Times New Roman,serif">
      <?=$subject[0]."&nbsp;&nbsp;>>&nbsp;&nbsp;".$subject[1];?>
      </font></td>
    <td width="150" height="30"> <font color="#000033" size="2" face="Georgia,Times New Roman,serif">
      <?=$row[3];?>
      </font></td>
    <td width="150" height="30"> <font color="#000033" size="2" face="Georgia,Times New Roman,serif">
      <?=$row[8];?>
      </font></td>
  </tr>

  <?
    }
    
?>

</table>
<tr align="left" valign="middle">
           <td>&nbsp;</td>
             </tr>



Just unsure on how to modify this to show request id, school, class, description in the table...any help would be much appreciated.

This post has been edited by King8654: 16 Jul, 2008 - 11:55 AM
User is offlineProfile CardPM

Go to the top of the page


JBrace1990
post 16 Jul, 2008 - 12:23 PM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 380



Thanked 16 times

Dream Kudos: 350
My Contributions


what you want to do is pull info from the database in the while loop, but it needs to be more like this:
php

while($row = mysql_fetch_array($sql)
{
echo "<tr><td>".$row['row_name']."</td><td>";
//(etc, etc. just replace the name with what you need)
}
User is offlineProfile CardPM

Go to the top of the page

King8654
post 16 Jul, 2008 - 12:52 PM
Post #3


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 89


My Contributions


Actually got it i think, just gotta modify it little more for subject name and the fill request link

CODE

<?php

$query = "SELECT school,class,description FROM requests";

$result = mysql_query($query) or die(mysql_error());
echo "<table border='1'>";
echo "<tr><th>School</th><th>Class</th><th>Description</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>";
echo $row['school'];
echo "</td><td>";
echo $row['class'];
echo "</td><td>";
echo $row['description'];
echo "</td></tr>";
}
echo "</table>";
//}
?>


This post has been edited by King8654: 16 Jul, 2008 - 02:11 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/30/08 02:51AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month