![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
totally newbie need help with searching from Mysql databasei have database ICT with table news and consist off id,title, abstraksi(news synopsys),content, datetime and photo and publish (news will be published or not). I want to divide the search result 10 result per page but it doesnt work. whats wrong with this program.. How to make search option which selected by user search by title. I have datetime format how to print only date or only news time from database. If i change the field datetime with field date and field time. How to sort lastest news .
<html> <head><title></title></head> <body> <form action = search_news.php method = post> </table> <tr> <td >Search</td> <td><input type = text name = keyword size = 20 ></td> <td> <select name=id class=textfield>"; <?php echo "<option value = ".$arr_topic[$i][id]; if ($id == $arr_topic[$i][id]) { echo " selected"; } echo ">".$arr_topic[$i][kategori]."</option>"; } echo "</select> ?> </td> <td><input type = submit name = submit value = Go ><td> </tr> </table> </form> <?php $user = "root"; $host = "localhost"; $pass = ""; $connection = mysql_connect($host,$user,$pass); $query = "select * from news where title like '%keyword%' or abstraksi like '%keyword%'and publish == 'Y'"; $nb_result = mysql_query($query); $nb_row_found = mysql_num_rows($nb_result); $rowperpage = 10; //nb news per page if (empty($offset)){ $offset = 0; } if ($nb_row_found==0){ echo "<b>$keyword</b> doesn't matched any news"; exit; } else{ echo "<b>$keyword</b><br> found ".$nb_row_found.""; } //get result $result = mysql_query("select * from news where title like '%$skeyword%' or abstraksi like '%$keyword%'order by id limit $offset,$rowperpage"); echo "<table align = center><h2>News found : </h2>"; echo "<table border = 0 >"; while($row_result = mysql_fetch_arrray($result)) { echo "<tr>"; echo "<td>"; echo "<a href =\"$self?id=$row_result[id]\ >".$row_result[title]."</a>"; echo $row_result[abstraksi];//abstraksi echo "<td>"; echo "<tr><td align = right>"; echo "</td></tr>"; } echo "</table>"; echo "<div align = center>"; if ($offset != 0){ $prevoffset = $offset-$rowperpage; echo "<a href = $PHP_SELF?offset= $prevoffset>Prev</a><nobr>"; } //count pages $max_page = ceil($nb_row_found/$rowperpage); for ($i = 1;$i <= $maxpage;$i++){ $newoffset = $rowperpage * ($i -1); if ($offset != $newoffset){//print link to page echo "<a href = $PHP_SELF?offset = $newoffset>$i</a></nobr>"; } else{//print without link echo " ".$i." "; } if ((!($offset/$rowperpage) + 1 == $max_page)&& $maxpage != 1 ){ $newoffset = $offset + $rowperpage; echo "<a href = $PHP_SELF?offset = $newoffset>Next</a><nobr>"; echo "</div>"; } } ?> </body> </html> |
|||
|
#2
|
|||
|
|||
|
sorry I should deleted some of thesource code. this is the source code.
<html> <head><title></title></head> <body> <form action = search_news.php method = post> //this link doesn't work. I want, i can search from the search page. Pls help.. </table> <tr> <td >Search</td> <td><input type = text name = keyword size = 20 ></td> <td> </td> <td><input type = submit name = submit value = Go ><td> </tr> </table> </form> <?php $user = "root"; $host = "localhost"; $pass = ""; $connection = mysql_connect($host,$user,$pass); $query = "select * from news where title like '%keyword%' or abstraksi like '%keyword%'and publish == 'Y'"; $nb_result = mysql_query($query); $nb_row_found = mysql_num_rows($nb_result); $rowperpage = 10; //nb news per page if (empty($offset)){ $offset = 0; } if ($nb_row_found==0){ echo "<b>$keyword</b> doesn't matched any news"; exit; } else{ echo "<b>$keyword</b><br> found ".$nb_row_found.""; } //get result $result = mysql_query("select * from news where title like '%$skeyword%' or abstraksi like '%$keyword%'order by id limit $offset,$rowperpage"); echo "<table align = center><h2>News found : </h2>"; echo "<table border = 0 >"; while($row_result = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>"; echo "<a href = view($row_result[id]) >".$row_result[title]."</a>"; /* i want to make a function to view news content which id = $row_result[id] can i call it like this ??? */ echo $row_result[abstraksi];//abstraksi echo "<td>"; echo "<tr><td align = right>"; echo "</td></tr>"; } echo "</table>"; echo "<div align = center>"; if ($offset != 0){ $prevoffset = $offset-$rowperpage; echo "<a href = $PHP_SELF?offset= $prevoffset>Prev</a><nobr>"; } //count pages /*i have get the result of the search but if the result more than 1 page i still don't get link to next page result whats wrong here?? pls help*/ $max_page = ceil($nb_row_found/$rowperpage); for ($i = 1;$i <= $maxpage;$i++){ $newoffset = $rowperpage * ($i -1); if ($offset != $newoffset){//print link to page echo "<a href = $PHP_SELF?offset = $newoffset>$i</a></nobr>"; } else{//print without link echo " ".$i." "; } if ((!($offset/$rowperpage) + 1 == $max_page)&& $maxpage != 1 ){ $newoffset = $offset + $rowperpage; echo "<a href = $PHP_SELF?offset = $newoffset>Next</a><nobr>"; echo "</div>"; } } ?> </body> </html> // how to make an option search news by title or by content? //thank you |
|
#3
|
|||
|
|||
|
there is still mistakes keyword should be $keyword.
Please help ![]() |
|
#4
|
||||
|
||||
|
You had a few other typos in your code. Your general idea of how you needed to go about this project was good. You should have made use of $_POST and $_GET variables to get your keyword and offset from the URL, so that these values are carried on from view to view as you click on the links provided by your search page. Also, you need to be careful to use quotes in your HTML code where they should be used - I had to make ALOT of fixes in this area, in order to get your code to work. You must not put spaces in your URLs - especially when trying to set variables like 'offset' for your PHP code to retrieve using $_GET.
One last item, be careful when writing MySQL queries that you don't use the double equal sign - it doesn't work. Just use a single equal sign when checking a condition. Anyway, there were so many things to fix in the code, here's a posting of your code, corrected. I put comments with __JM__ where I made changes: PHP Code:
|
|
#5
|
||||
|
||||
|
By the way, in the above code, where you see [ENT_0], replace those with ampersands (just do a search & replace). I don't know why this is happening here - probably just a small bug in the forum code that can be fixed up.
|
|
#6
|
||||
|
||||
|
Aaargh!
Noted... __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#7
|
|||
|
|||
Did you get your script to work?I spotted other typos in your html
All html variables should be somename="quoted" or else(depending on the users browser )the form will not submit them to the script in the first place. your script won't give the right output if it doesn't get the right input. Drop us a line and let us know if you got anywhere. Last edited by JUNK KED : 05-Jan-2005 at 02:52.
Reason: correction
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cgi txt database to mysql | erhanharputlu | MySQL / PHP Forum | 0 | 27-Sep-2004 02:30 |
| Macromedia DWMX and PHP MySQL setup | soulja90 | MySQL / PHP Forum | 1 | 17-Mar-2004 05:50 |
| Grouping data from MySQL with PHP - Newbie question. | giobbi | MySQL / PHP Forum | 12 | 27-Feb-2004 01:34 |
| Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More | EyotaHosts | Web Hosting Advertisements & Offers | 0 | 28-Jun-2003 14:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The