Forum Moderators: coopster

Message Too Old, No Replies

Need to display all comments of the user chosen date

PLEASE HELP: HTML and PHP Code provided

         

shruti

8:00 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



HTML code
comments.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title><style type="text/css">
<!--
body {
background-image: url(modern-pink-floral.jpg);
}
.style1 {
font-family: Elephant;
color: #CC0066;
}
-->
</style>

</head>

<body>

<p>&nbsp;</p>
<p>&nbsp;</p>
<form method=post name=f1 action='datecomments.php'>
<p align="center" class="style1">
<input type=hidden name=todo value=submit />
PLEASE SELECT A DATE</p>
<table width="367" border="0" align="center" cellspacing="0" bordercolor="#CC0066" >
<tr><td width="113" align=left ><div align="center">
<select name="month" id="month" value='MONTH' style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option>----Month----</option>


Select Month



<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='04'>April</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>August</option>
<option value='09'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
</div></td>
<td width="84" align=left > <select name="date" id="date" style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option selected="selected">--Date--</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select></td><td width="164" align=left ><label>
<select name="year" id="year" style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option selected="selected">----Year----</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
</select>
</label>
<input type=submit id="submit" class="formbutton" value=Submit>
</table>

.<style type="text/css">

.formbutton{
cursor:pointer;
border:outset 3px #ccc;
background:#999;
color:#666;
font-weight:bold;
padding: 2px 5px;
background:url(media/formbg.gif) repeat-x left top;
}

</style>
<div align="center"></div>
</form>
</body>
</html>

-===========================================================

php code
<?php

$host = "localhost";
$user = "";
$pass = "";
$dbname = "";

$connection = mysql_connect("localhost", "root", "") or die("Cannot connect to MySQL

server: " . mysql_error());
$db_selected = mysql_select_db('tmetrix', $connection);

$month = $_POST['month'];
$date = $_POST['date'];
$year = $_POST['year'];

$whole1="$year-$month-$date";

echo "$whole1";

if (isset($_POST['submit']))

$data = mysql_query("SELECT * FROM comments where date = '$whole'") or

die(mysql_error());
Print "<table border=0 cellspacing=0 cellpadding=0 width=761 style='width:570.75pt'>";


$num_data = mysql_num_rows($data);
for ($i=0; $i <$num_data; $i++)
{

$row = mysql_fetch_array($data);

echo "<tr><td bgcolor='#D2DCFB'>" .$row['CELLID'] . "</td> ";
echo "<td bgcolor='#D2DCFB'>" .$row['problem'] . "</td> ";
echo "<td bgcolor='#D2DCFB'>" .$row['solution'] . "</td> ";
echo "<td bgcolor='#D2DCFB'>" .$row['comments'] . "</td></tr> ";
}

?>

ERROR:
--
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\WAMP\www\tmetrix\datecomments.php on line 28

[edited by: eelixduppy at 8:11 pm (utc) on July 9, 2008]
[edit reason] removed db specifics [/edit]

danbair

8:59 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



I can't be sure, but off the top of my head I think that the problem may be that your field is titled 'date' which is a reserved word. Try changing the field's name to something else, such as 'created', and then test that out.

If you're still getting an error, echo out your query, and use phpMyAdmin to see if it works in there, then you can get a better hint as to why it's not working.

shruti

12:33 pm on Jul 10, 2008 (gmt 0)

10+ Year Member



Thanks for reply BUT:
I have echo'ed the word WHOLE which does echo off the date as 2008-2-12(e.g) So may be the word "date" is not causing a problem here.
But i cant figure what is the problem here. it might be a small one but I am not able to figure out.

PLEase HELP ME SOMEONE!

dreamcatcher

1:40 pm on Jul 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your are setting the date as $whole1, but accessing the var in the query as $whole:

$data = mysql_query("SELECT * FROM comments where date = '$whole'") or

should be:

$data = mysql_query("SELECT * FROM comments where date = '$whole1'") or

dc

shruti

8:56 pm on Jul 10, 2008 (gmt 0)

10+ Year Member



thank you v much
stupid prob! Damn me