pixeltrace Posted February 19, 2007 Share Posted February 19, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/ Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 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'];?> Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188566 Share on other sites More sharing options...
pixeltrace Posted February 19, 2007 Author Share Posted February 19, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188575 Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 For the total numbers its a simple. $sql = mysql_query("SELECT * FROM `members`"); $num = mysql_num_rows($sql); and the drop down, can you explain that again please thanks. Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188579 Share on other sites More sharing options...
pixeltrace Posted February 19, 2007 Author Share Posted February 19, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188584 Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 EDITED: so you basically want to use the drop down as a way to search your database? Like from name, client id and/or date? I didn t mean search i meant display! Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188589 Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 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.""); Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188593 Share on other sites More sharing options...
pixeltrace Posted February 19, 2007 Author Share Posted February 19, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188601 Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 $sql = mysql_query("SELECT * FROM `table` WHERE `var`='value' ORDER BY ".$display_order." ".$order_type.""); ?> you need to put your query in there and add ORDER BY ".$display_order." ".$order_type on the end Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188603 Share on other sites More sharing options...
pixeltrace Posted February 19, 2007 Author Share Posted February 19, 2007 sorry bro, i'm totally lost and dont know where and how to start. hope you could help me with this. thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/39159-problem-on-displaying-data-from-database/#findComment-188614 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.