Jump to content


Photo

Gsearch, first bug


  • Please log in to reply
18 replies to this topic

#1 Unreal

Unreal

    like.. TOTally cool!

  • Members
  • Pip
  • 241 posts

Posted 19 October 2004 - 02:11 PM

Yello,
Well i decided illd go ahead with my game releated search thing, and ive came accross my first bug which i have no idea to fix it, ok so lemme explain :
A user types in a games name, into a textbox, he clicks search, and the results pop up.. thats fine right? BUT IT ISNT XD now im getting to the point. If someone types a games name and we dont have stuff for that game, a blank page appears, how do i make it say " sorry no information found" .. i no it must be easy.. but i cant figure it out..
here's the current code :

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","*****","******"); 
	
//select which database you want to edit
mysql_select_db("cheats"); 

$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM cheat WHERE title LIKE '%$search%'");

//grab all the content
while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $title=$r["title"];
   $message=$r["cheat"];
   $who=$r["website"];
   $date=$r["date"];
   
   //display the row
   echo "$title <br> $message <br> $who <br> $date";

}
?>


#2 theguid

theguid

    chewy

  • Members
  • Pip
  • 296 posts
  • Gender:Male
  • Location:Dalton, GA

Posted 19 October 2004 - 02:30 PM

I dont know much php, but instead of a while statement can you use an if-else statement? The default case could be to return a 'nothing found' message and the if statement could just have a break at the end of it if the condition was met (it found a match).

#3 Unreal

Unreal

    like.. TOTally cool!

  • Members
  • Pip
  • 241 posts

Posted 19 October 2004 - 02:36 PM

well below the echo of the results, i tried this -
if $result == null then
echo "sorry no results found"

but that didnt work..

#4 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 19 October 2004 - 03:11 PM

Here, try this....

<?PHP
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","*****","******");

//select which database you want to edit
mysql_select_db("cheats");

$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM cheat WHERE title LIKE '%$search%'");

	//BEGIN JAYMZ'S EDITS

	if($search)
	{

	//END JAYMZ'S EDIT

//grab all the content
while($r=mysql_fetch_array($result))
{
  //the format is $variable = $r["nameofmysqlcolumn"];
  //modify these to match your mysql table columns
 
  $title=$r["title"];
  $message=$r["cheat"];
  $who=$r["website"];
  $date=$r["date"];
 
  //display the row
  echo "$title <br> $message <br> $who <br> $date";

}

//BEGIN JAYMZ'S EDIT2

if(!$result)
{echo "We're sorry, there were no results for that search.";}

}

//END JAYMZ'S EDIT2

?>

Edited by Jaymz, 19 October 2004 - 03:18 PM.


#5 Dabu

Dabu

    Young Padawan

  • Members
  • Pip
  • 148 posts
  • Location:Greensboro, North Carolina

Posted 19 October 2004 - 03:14 PM

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","*****","******");

//select which database you want to edit
mysql_select_db("cheats");

$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM cheat WHERE title LIKE '%$search%'") or die("Mysql Error: " . mysql_error());

$numresults = mysql_num_rows($result);

if ($numresults < 1) {
echo "Error, no results found!";
exit();
} else {

//grab all the content
while($r=mysql_fetch_array($result))
{
  //the format is $variable = $r["nameofmysqlcolumn"];
  //modify these to match your mysql table columns
 
  $title=$r["title"];
  $message=$r["cheat"];
  $who=$r["website"];
  $date=$r["date"];
 
  //display the row
  echo "$title <br> $message <br> $who <br> $date";

}
}
?>


Give that code a try. Basicly its counting the number of rows affected by the search query, then if the number of rows affected is 0, it returns "Error, No Results Found" and stops loading the page (exit). Otherwise it will resume with the display of the results as normal.

#6 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 19 October 2004 - 03:19 PM

Wow more complex than mine :blink:

#7 Dabu

Dabu

    Young Padawan

  • Members
  • Pip
  • 148 posts
  • Location:Greensboro, North Carolina

Posted 19 October 2004 - 04:29 PM

thats cuz i pwnzor you :blink:

#8 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 19 October 2004 - 04:57 PM

:blink:

#9 Unreal

Unreal

    like.. TOTally cool!

  • Members
  • Pip
  • 241 posts

Posted 20 October 2004 - 10:24 AM

Thanks Dabu, your worked great :blink: Thanks jaymz for trying :)

#10 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 20 October 2004 - 03:40 PM

No problem :blink:

#11 Dabu

Dabu

    Young Padawan

  • Members
  • Pip
  • 148 posts
  • Location:Greensboro, North Carolina

Posted 20 October 2004 - 04:29 PM

Hah I win! Score is one Dabu none for Jaymz! Back on subject, no problem here to help anytime (just ask Faken or Jay how much I love to code! :blink:)

#12 Unreal

Unreal

    like.. TOTally cool!

  • Members
  • Pip
  • 241 posts

Posted 21 October 2004 - 11:38 AM

:) Thanks again :) Ill probly get some more bugs soon.. when i finnish this part..

#13 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 21 October 2004 - 02:39 PM

NP again :), I can do basic php, but I spent 45mins last night trying to limit the amount of times a loop would loop and select from a database, when all I needed was "LIMIT 5" :)

#14 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 02 November 2004 - 01:36 PM

Jaymz, Dabu roX0rz, and your still pretty new so of course he will pwn you :D

#15 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 02 November 2004 - 04:25 PM

Maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Dabu doesn't pwn me, the sheep does :D Yeah, that's right, I have the kickass sheep miniavatar :D

#16 Dabu

Dabu

    Young Padawan

  • Members
  • Pip
  • 148 posts
  • Location:Greensboro, North Carolina

Posted 02 November 2004 - 05:35 PM

the cow pwns all, am I am the master of the cows

MOOOOOO

#17 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 03 November 2004 - 01:03 PM

Its funny because no one knows what the little icons are all about! :D

#18 Unreal

Unreal

    like.. TOTally cool!

  • Members
  • Pip
  • 241 posts

Posted 03 November 2004 - 01:53 PM

New member / profile system or even a chat or something? XD

#19 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 03 November 2004 - 04:05 PM

Just giving more customization to the users really.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users