Jump to content

Recommended Posts

[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

Try this:

[code]<?php
function 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

[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]
<?php
if (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

Sorry if I offended you. Anyways give this a try

[code]
<?php
if (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

no  ;) i wasnt offended, i really appreciate the help, let me give this a try :D


edit: no, still nothing  :'(  :'(  :'(  :'(  here is the EXACT code i used...

[code]
<?php include ('../nect.php');?>
<?php
if (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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.