Jump to content

problem on displaying data from database


pixeltrace

Recommended Posts

guys,

 

i need help, i cant get the correct method on how to display items in my database in my table.

the error message that i am getting is "no data found"

 

also, i have a drop down option wherein i can view the datas by

name

clientID

reg date ( day, month, year is on a separate field in my database)

 

i also have a section there wherein it has to show the total number of items in the database

but i dont know how to make it work too.

 

below is my codes for this page

 

<table width="620" border="0" cellspacing="2" cellpadding="0">
                <tr>
                  <td colspan="6"><table width="616" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="329" class="text6">    total record found : <? '' ?></td>
                      <td width="287"> </td>
                    </tr>
                  </table></td>
                  </tr>
                <tr>
                  <td colspan="6"><table width="617" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="459"> </td>
                      <td width="158" class="text6">sort by : 
                        <select name="select">
					<option value="clientmngr.php?id=v1">name</option>
					<option value="clientmngr.php?id=v2">client ID</option>
					<option value="clientmngr.php?id=v3">reg date</option>
                      </select>                        </td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td colspan="6"> </td>
                  </tr>
                <tr>
                  <td width="52" align="center" bgcolor="#83C2ED" class="text5">ID</td>
                  <td width="160" align="center" valign="top" bgcolor="#83C2ED" class="text5">name</td>
                  <td width="69" align="center" bgcolor="#83C2ED" class="text5">joined date </td>
                  <td width="153" align="center" bgcolor="#83C2ED" class="text5">rate agreed </td>
                  <td width="133" align="center" bgcolor="#83C2ED" class="text5">remark</td>
                  <td width="39" bgcolor="#83C2ED"> </td>
                </tr>
<?
include 'db_connect.php';

$uSql = "SELECT clientid, client_name, joined_day, joined_month, joined_year, client_rate, client_remarks FROM clients ORDER by client_name DESC";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
}
else{   	 
while($uRow = mysql_fetch_row($uResult)){		
?>             <tr>
                  <td bgcolor="#FFFFCC" class="text8">C<?= $uRow[0]?></td>
                  <td bgcolor="#FFFFCC" class="text8"><?= $uRow[1]?></td>
                  <td bgcolor="#FFFFCC" class="text8"><?= $uRow[2]?>-<?= $uRow[3]?>-<?= $uRow[4]?></td>
                  <td bgcolor="#FFFFCC" class="text8"><?= $uRow[5]?></td>
                  <td bgcolor="#FFFFCC" class="text8"><?= $uRow[6]?></td>
                  <td align="center" bgcolor="#FFFFCC"><a href="clientedit.php?$clientid=$clientid" class="link1">edit</a></td>
                </tr>
<?        
}
} 
?>
                <tr>
                  <td colspan="6"> </td>
                  </tr>
                <tr>
                  <td colspan="6"> </td>
                </tr>
              </table>

 

 

hope you could help me with this.

 

thanks in advance!

Link to comment
Share on other sites

your missing ; on your variables..

<?= $uRow[0]?>

 

should look like this

<?=$uRow[0];?>

 

I also think you should use an array, and then you

can change those to field names from the table

 

example:

while($uRow = mysql_fetch_array($uResult))
{
  echo ""; //info here
}

 

You can then use this...

<?=$uRow['field_name'];?>

Link to comment
Share on other sites

ic. thanks!

its working now.

 

i still got 2 more problems.

 

notice in my codes

 

i got a select form there

                      <select name="select">
                          <option value="clientmngr.php?id=v1">name</option>
                          <option value="clientmngr.php?id=v2">client ID</option>
                          <option value="clientmngr.php?id=v3">reg date</option>
                        </select>

 

i am planning to use it as a option to view the data via:

name

client id

reg date (day, month, year is separated from the databse field)

 

i dont know how to do it.

 

also what is the code that will display the total number of items in my database

let say via clientid?

 

thanks in advance!

Link to comment
Share on other sites

for the drop down menu, i have this code
code]sort by :
                      <select name="select">
                          <option value="1">name</option>
                          <option value="2">client ID</option>
                          <option value="3">date</option>
                        </select>[

 

i will use this so i may have the option to view the data

sorted via name, client id or date

 

but i dont know what is the codes to make the drop down menu

function correctly.

 

hope you could help me with this.

 

thanks!

Link to comment
Share on other sites

To display from your choice just do the following

 

$display_order = $_POST['select'];

$order_type  = "ASC";

you can make the order_type ASC or DESC upto you.

 

$sql = mysql_query("SELECT * FROM `table` WHERE `var`='value' ORDER BY ".$display_order." ".$order_type."");

Link to comment
Share on other sites

hi,

 

i dont understand and how to place this in my page.

im still in the process of learning.

this is the codes for my page

<table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="../images/spacer.gif" width="6" height="10"></td>
    <td><table width="216" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1"></td>
      </tr>
      <tr>
        <td align="left" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1"></td>
        <td width="214" valign="top"><table width="620" border="0" cellspacing="2" cellpadding="0">
            <tr>
              <td colspan="6"><table width="616" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="329" class="text6">
				 <? $sql = mysql_query("SELECT * FROM 'clients' ");
$num = mysql_num_rows($sql);
?>


				total record found : <?= $uRow[0]?>
                      
				  
				  </td>
                    <td width="287"> </td>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <td colspan="6"><table width="617" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="459"> </td>
                    <td width="158" class="text6">sort by :

				<? $display_order = $_POST['select'];
				$order_type   = "ASC";
		$sql = mysql_query("SELECT * FROM `table` WHERE `var`='value' ORDER BY ".$display_order." ".$order_type."");
?>
                      <select name="select">
                          <option value="1">name</option>
                          <option value="2">client ID</option>
                          <option value="3">reg date</option>
                        </select>
                    </td>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <td colspan="6"> </td>
            </tr>
            <tr>
              <td width="52" align="center" bgcolor="#83C2ED" class="text5">ID</td>
              <td width="160" align="center" valign="top" bgcolor="#83C2ED" class="text5">name</td>
              <td width="69" align="center" bgcolor="#83C2ED" class="text5">joined date </td>
              <td width="153" align="center" bgcolor="#83C2ED" class="text5">rate agreed </td>
              <td width="133" align="center" bgcolor="#83C2ED" class="text5">remark</td>
              <td width="39" bgcolor="#83C2ED"> </td>
            </tr>
            <?
include 'db_connect.php';

$uSql = "SELECT clientid, client_name, day_joined, month_joined, year_joined, client_rate, client_remarks FROM clients ORDER by client_name DESC";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
    echo 'no data found';
}
else{   	 
while($uRow = mysql_fetch_row($uResult)){		
?>
            <tr>
              <td bgcolor="#FFFFCC" class="text8"> C
                <?= $uRow[0]?></td>
              <td bgcolor="#FFFFCC" class="text8"> 
                  <?= $uRow[1]?></td>
              <td bgcolor="#FFFFCC" class="text8"> 
                  <?= $uRow[2]?>
                -
                <?= $uRow[3]?>
                -
                <?= $uRow[4]?></td>
              <td bgcolor="#FFFFCC" class="text8"> 
                  <?= $uRow[5]?></td>
              <td bgcolor="#FFFFCC" class="text8"> 
                  <?= $uRow[6]?></td>
              <td align="center" bgcolor="#FFFFCC"><a href="clientedit.php?$clientid=$clientid" class="link1">edit</a></td>
            </tr>
            <?        
}
} 
?>
            <tr>
              <td colspan="6"> </td>
            </tr>
            <tr>
              <td colspan="6"> </td>
            </tr>
        </table></td>
        <td align="right" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1"></td>
      </tr>
      <tr>
        <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1"></td>
      </tr>
    </table></td>
    <td><img src="../images/spacer.gif" width="6" height="10"></td>
  </tr>
</table>

 

i placed the code that you gave me but i'm not sure if this is correct since its still not working.

 

thanks in advance!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.