I am having a problem with my search script. At current it will simply search by a selected date which is a java based calendar that displays when using id='datedisplay' in the input form field below. What I want it to do is have an extra input text field box that can search for text/words within a table field. So my query would be something like Code: SELECT * FROM tbl_comments WHERE comments_date LIKE '%$search%' OR comments_content LIKE '%$textsearch%' ORDER BY comments_date DESC, comments_time DESC But now it gets tricky. I want it to work so if someone types something into the text input box, it will ignore the other input box that searches by date. And if the text input search box is empty, it will ignore the text input box and search only by the date input box.
I am assuming it's going to involve some if statements and posssible !empty and }else{ commands, I am just not 100% sure how to piece what I want together within my search code below.
Here is my form code:Code: echo "<form method='post' action='handover_index.php'>";
echo "<input type='text' name='search' id='datedisplay' style='width: 60px;' maxlength='10'> ";
echo "<input type='hidden' name='cmd' value='search' />";
echo " <input type='Submit' name='submit' value='Go!'>";
echo "</form>";
And here is my php code:Code: // ##### Search DB ##### Start ->
$str = str_replace("n", "<BR />", $str);
if (strlen($_POST["search"]) > 1 or strlen($_GET["search"]) > 1)
{
if(isset($_POST["search"])) $search=$_POST["search"];
if(isset($_GET["search"])) $search=$_GET["search"];
$result = mysql_query("SELECT * FROM tbl_comments WHERE comments_date LIKE '%$search%' ORDER BY comments_date DESC, comments_time DESC");
echo "<table width='98%' cellspacing='0' cellpadding='3' border='0'>";
$i = 0;
while($r=mysql_fetch_array($result))
{
$comments_id=$r["comments_id"];
$comments_date=$r["comments_date"];
$comments_time=$r["comments_time"];
$comments_user=$r["comments_user"];
$comments_content=str_replace("rn","
",$r[comments_content]);
$comments_updateuser=$r["comments_updateuser"];
$comments_updatedate=$r["comments_updatedate"];
$comments_updatetime=$r["comments_updatetime"];
list($thour, $tmin, $tsec) = explode(':', $comments_time);
list($uthour, $utmin, $utsec) = explode(':', $comments_updatetime);
if ($_GET[cmd]== "edit" and $_GET[comments_id] == $comments_id) {
$comments_content=str_replace("
","rn",$r[comments_content]);
echo "<tr>";
echo "<form action='handover_index.php' method='post'>";
echo "<td class='rowtxt' valign='top' width='375'><font class='rowadded'>Added</font> <font class='rowaddeddata'>$comments_date</font> <font class='rowadded'>at</font> <font class='rowaddeddata'>$comments_time</font> <font class='rowadded'>by</font> $comments_user</td>";
echo "<td class='rowtxt' valign='top' width='45'><div class='rowalign'><input type=submit name=submit value=Update><input type=hidden name=comments_id value=$comments_id></div></td>";
echo "<tr></tr>";
echo "<td class='rowtxt' valign='top' colspan='2' width='100%'><textarea name=comments_content cols='10' rows='5'>$comments_content</textarea>
</td>";
echo "</form>";
echo "</tr>";
}else{ if($i%2 == 0){
echo "<tr class='rowresult1'>";
echo "<td class='txt' valign='top' width='375'> <font class='rowadded'>Added</font> <font class='rowaddeddata'>$comments_date $thour:$tmin</font> - $comments_user";
if (!empty($comments_updateuser)) {
echo "<font size='2' color='#000000'> / </font> <font class='rowadded'> Updated</font> <font class='rowaddeddata'>$comments_updatedate $uthour:$utmin</font> - " .$comments_updateuser. "";
}
echo "</td>";
echo "<td class='rowtxt' valign='top' width='45'><div class='rowalign'><INPUT TYPE='button' name='edit' value='Edit' onClick=self.location='handover_index.php?cmd=edit&comments_id=$comments_id&search=$search'></div></td>";
echo "</tr><tr class='rowresult1'>";
echo "<td class='rowtxt' colspan='2' valign='top' width='100%'>$comments_content
";
echo "</td></tr>";
$i++;
}else{
echo "<tr class='rowresult2'>";
echo "<td class='txt' valign='top' width='375'> <font class='rowadded'>Added</font> <font class='rowaddeddata'>$comments_date $thour:$tmin</font> - $comments_user";
if (!empty($comments_updateuser)) {
echo "<font size='2' color='#000000'> / </font> <font class='rowadded'> Updated</font> <font class='rowaddeddata'>$comments_updatedate $uthour:$utmin</font> - " .$comments_updateuser. "";
}
echo "</td>";
echo "<td class='rowtxt' valign='top' width='45'><div class='rowalign'><INPUT TYPE='button' name='edit' value='Edit' onClick=self.location='handover_index.php?cmd=edit&comments_id=$comments_id&search=$search'></div></td>";
echo "</tr><tr class='rowresult2'>";
echo "<td class='rowtxt' colspan='2' valign='top' width='100%'>$comments_content
";
echo "</td></tr>";
$i++;
}
}
}
echo "</table>";
echo "
";
}else{
// ##### Search DB ##### End <-
Storing/displaying image urls in a database?
HiBasically I have the following scenario:User chooses picture from list. Picture info is added into the db, including url.However I can't figure out how exactly i should be storing the url for the
Ajax not working on IE 6 for Windows CE
I've created a webpage which uses the classis Ajax in following format:view plaincopy to clipboardprint?function mytest() { try { xmlHTTP = new XMLHttpRequest(); } catch (e) {
dinamic "textboxes"?
Ey all, my first post here, i hope its not a hard one I display mysql results in a tableEach row has a link which must send the title of the row to "result.php"
onClick='location.href=index.htm'> not working
Below is my code:echo "<input type='button' value='redirect' onClick='location.href=index.htm'>";what is wrong with the code?? it's not working
Transport data between itab and textfield on ALV event
Hallo,
checkbox update
I am having a brain fart right now and i cant remember how to do this. if anyone could help that would be great. I have search google and this forum but have not found what i am looking for.thankswhen
file downloaded can't be read !!
<?php $fileName = 'mypic.jpg';$mimeType = 'image/jpeg';header('content-disposition: attachment; filename=' . $fileName);header('content-type: ' . $mimeType);header('content-length: ' .
Looking for help reading a .txt or .ini file and outputting the info.
I have a file called Info.ini and It has the following info:Code: [General]Online=0I would like it to be in a php file as just 0 if possible. Also how would I do this from php file to php file and let
smart reading from a text file
Hello there fellow coders, i was wondering if one of you wouldnt mind helping me with this problem i seem to have hit:There is an application which i am currently coding, which writes everything that
php/mysql problem
Hey all,Problem: im trying to setup a shop where people can use a drop-down list to select the amount of items they would like to purchase, then when they click on the "buy" button it uses