Lynk Posted August 16, 2006 Share Posted August 16, 2006 [font=tahoma]i wrote this little thingie, when i move the [b]echo[/b] part, out of the [b]if (){ }[/b] part way below, it works, but i just cant seem to get it working with the [b]if[/b]....[/font]anyone?[code]<? function select5(){ $select5 = "SELECT * FROM lynk_fm WHERE artist LIKE '%$q%' ORDER BY id $sort"; $obj5 = mysql_query($select5) or die($MySQLError.mysql_error()); return $obj5; } ?><form action="<?=$PHP_SELF?>" name="form_search"><table width="100%" style="border:1px dashed darkgray;"><tr> <td width="222" bgcolor="#EEEEEE">Music search</td></tr><tr><td valign="top"><input name="q" type="text" class="INPUT" onFocus="if(this.value=='Tiesto')this.value='';" value="Tiesto"><select name="sort" class="I_send"> <option value="DESC">Newest first</option> <option value="ASC">Oldest first</option></select><input type="submit" class="I_send" value="Go >"> Search for music on Lynk Fm <br /></td></tr></table></form><? if($_POST['q'] != "") {?><? $res5 = select5(); while($row5 = mysql_fetch_object($res5)) { echo "$row5->song<br>"; } ?><? } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/ Share on other sites More sharing options...
Orio Posted August 16, 2006 Share Posted August 16, 2006 Try this:[code]<?phpfunction select5($q,$sort){ $select5 = "SELECT * FROM lynk_fm WHERE artist LIKE '%$q%' ORDER BY id $sort"; $obj5 = mysql_query($select5) or die($MySQLError.mysql_error()); return $obj5;}if($_POST['q'] != "") {$res5 = select5($_POST['q'],$_POST['sort']);while($row5 = mysql_fetch_object($res5)){echo "$row5->song<br>";}?><form action="<?=$PHP_SELF?>" name="form_search"><table width="100%" style="border:1px dashed darkgray;"><tr> <td width="222" bgcolor="#EEEEEE">Music search</td></tr><tr><td valign="top"><input name="q" type="text" class="INPUT" onFocus="if(this.value=='Tiesto')this.value='';" value="Tiesto"><select name="sort" class="I_send"> <option value="DESC">Newest first</option> <option value="ASC">Oldest first</option></select><input type="submit" name="submit" class="I_send" value="Go >"> Search for music on Lynk Fm <br /></td></tr></table></form>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75556 Share on other sites More sharing options...
Lynk Posted August 16, 2006 Author Share Posted August 16, 2006 no man, still nothing...the page just loads quickly, and the url shows thishttp://lynkonline.atlas2wielers.nl/lynk_fm/lynk_fm2.php?q=Tiesto&sort=DESC&submit=Go+%3E Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75580 Share on other sites More sharing options...
Lynk Posted August 16, 2006 Author Share Posted August 16, 2006 [quote author=Lynk link=topic=104462.msg416700#msg416700 date=1155720253]now it shows everything with tiesto in it...regardeless of the form...[/quote]no wait, it shows everything Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75582 Share on other sites More sharing options...
Lynk Posted August 16, 2006 Author Share Posted August 16, 2006 anyway, im really stuck this time...i just know its probably something soo silly... Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75583 Share on other sites More sharing options...
tomfmason Posted August 16, 2006 Share Posted August 16, 2006 well it is not silly. You just don't know. You need something like this[code]<?phpif (isset($_POST['submit'])) { //preform your code here}?><!--html here-->[/code] Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75586 Share on other sites More sharing options...
Lynk Posted August 16, 2006 Author Share Posted August 16, 2006 [quote author=tomfmason link=topic=104462.msg416707#msg416707 date=1155720838]well it is not silly. You just don't know. You need something like this[code]<?phpif (isset($_POST['submit'])) { //preform your code here}?><!--html here-->[/code][/quote]i actually do know, i DID have that the first time, that didnt work, so i switched to something more simpler...but i but it back now, you can check it here: http://lynkonline.atlas2wielers.nl/lynk_fm/lynk_fm2.php Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75587 Share on other sites More sharing options...
tomfmason Posted August 16, 2006 Share Posted August 16, 2006 Sorry if I offended you. Anyways give this a try[code]<?phpif (isset($_POST['submit'])) { $q = mysql_real_escape_string(trim($_POST['q'])); $sort = mysql_real_escape_string(trim($_POST['sort'])); if ((!$q) || (!$sort)) { echo "You did not submit a required field"; exit(1); } $select5 = "SELECT * FROM lynk_fm WHERE artist LIKE '%$q%' ORDER BY id $sort"; $obj5 = mysql_query($select5) or die(mysql_error()); while($row5 = mysql_fetch_assoc($obj5)){ echo '' . $row5['song'] . '<br />'; }} ?><form action="<?=$PHP_SELF?>" name="form_search"><table width="100%" style="border:1px dashed darkgray;"><tr> <td width="222" bgcolor="#EEEEEE">Music search</td></tr><tr><td valign="top"><input name="q" type="text" class="INPUT" onFocus="if(this.value=='Tiesto')this.value='';" value="Tiesto"><select name="sort" class="I_send"> <option value="DESC">Newest first</option> <option value="ASC">Oldest first</option></select><input type="submit" name="submit" class="I_send" value="Go >"> Search for music on Lynk Fm <br /></td></tr></table></form>[/code] Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75590 Share on other sites More sharing options...
Lynk Posted August 16, 2006 Author Share Posted August 16, 2006 no ;) i wasnt offended, i really appreciate the help, let me give this a try :Dedit: no, still nothing :'( :'( :'( :'( here is the EXACT code i used...[code]<?php include ('../nect.php');?><?phpif (isset($_POST['submit'])) { $q = mysql_real_escape_string(trim($_POST['q'])); $sort = mysql_real_escape_string(trim($_POST['sort'])); if ((!$q) || (!$sort)) { echo "You did not submit a required field"; exit(1); } $select5 = "SELECT * FROM lynk_fm WHERE artist LIKE '%$q%' ORDER BY id $sort"; $obj5 = mysql_query($select5) or die(mysql_error()); while($row5 = mysql_fetch_assoc($obj5)){ echo '' . $row5['song'] . '<br />'; }} ?><form action="<?=$PHP_SELF?>" name="form_search"><table width="100%" style="border:1px dashed darkgray;"><tr> <td width="222" bgcolor="#EEEEEE">Music search</td></tr><tr><td valign="top"><input name="q" type="text" class="INPUT" onFocus="if(this.value=='Tiesto')this.value='';" value="Tiesto"><select name="sort" class="I_send"> <option value="DESC">Newest first</option> <option value="ASC">Oldest first</option></select><input type="submit" name="submit" class="I_send" value="Go >"> Search for music on Lynk Fm <br /></td></tr></table></form>[/code] Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75618 Share on other sites More sharing options...
Lynk Posted August 16, 2006 Author Share Posted August 16, 2006 i just dont get it, the page must not like me or something, :P cuz all the other pages work fine ;Danyway, im tring to get this fixed for my [url=http://lynkonline.atlas2wielers.nl/preloader.php]still in beta site[/url] Link to comment https://forums.phpfreaks.com/topic/17715-simple-table-search/#findComment-75622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.