Jump to content


Photo

simple table search!


  • Please log in to reply
9 replies to this topic

#1 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 August 2006 - 07:40 AM

i wrote this little thingie, when i move the echo part, out of the if (){ } part way below,
it works, but i just cant seem to get it working with the if....


anyone?

<? 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>"; } ?>

<? } ?>


#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 16 August 2006 - 08:05 AM

Try this:

<?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>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 August 2006 - 09:15 AM

no man, still nothing...the page just loads quickly, and the url shows this

http://lynkonline.at...ESC&submit=Go >

#4 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 August 2006 - 09:25 AM

now it shows everything with tiesto in it...
regardeless of the form...


no wait, it shows everything

#5 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 August 2006 - 09:28 AM

anyway, im really stuck this time...

i just know its probably something soo silly...

#6 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 August 2006 - 09:33 AM

well it is not silly. You just don't know. You need something like this
<?php
if (isset($_POST['submit'])) {
   //preform your code here
}
?>
<!--html here-->

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#7 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 August 2006 - 09:36 AM

well it is not silly. You just don't know. You need something like this

<?php
if (isset($_POST['submit'])) {
   //preform your code here
}
?>
<!--html here-->


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.at...fm/lynk_fm2.php

#8 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 August 2006 - 09:49 AM

Sorry if I offended you. Anyways give this a try

<?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>

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#9 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 August 2006 - 11:26 AM

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...

<?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>


#10 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 August 2006 - 11:37 AM

i just dont get it, the page must not like me or something,  :P cuz all the other pages work fine ;D

anyway, im tring to get this fixed for my still in beta site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users