Jump to content

tarbender89

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tarbender89's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Back again! This forum was so helpful the last time I had a question (a whopping couple days ago, haha) that I'm wondering if you guys can help me out once again. My server version is 5.1. What I'm trying to do is add a line of code that will display "No results found." when the database returns no results after a search. Here's the current code for my search: mysql_connect ("localhost", "tarb89_admin", "leccums") or die (mysql_error()); mysql_select_db ("tarb89_ausus"); $term = $_POST['term']; $sql = mysql_query("SELECT `id`, `character_name`, `breed`, `gender`, `base_color`, `markings`, `genetics`, `sire`, `dam`, `other`, `player` FROM characters WHERE `player` LIKE '%$term%' OR `character_name` LIKE '%$term%' OR `id` LIKE '$term'") or die ('Error: '.mysql_error ()); while ($row = mysql_fetch_array($sql)){ echo '<br/><h2>'.$row['character_name']; echo '</h2> ID Number: '.$row['id']; echo '<br/>'.$row['gender']; echo '<br/>'.$row['breed']; echo '<br/>'.$row['base_color']; echo '<br/>'.$row['markings']; echo '<br/>'.$row['genetics']; echo '<br/>'.$row['sire']; echo ' x '.$row['dam']; echo '<br/>'.$row['other']; echo '<br/>'.$row['breed']; echo '<br/>Played by '.$row['player']; echo '<br/><br/>'; } I swear I've researched and researched this, but everything I try ends up in a MySQL error. The code posted above works fine and will display the correct results that were searched for; but if there were no results found in the database, it simply returns nothing. I'd like it to return "No results found." kinda thing. Thanks again!
  2. Oh goodness, you are my hero right now. I've been trying to get my little noob mind to wrap around this concept for weeks now. Thank you.. tremendously. This problem is finally solved!
  3. MySQL Version: 5.1 $database="tarb89_ausus"; mysql_connect ("localhost", "tarb89_admin", "leccums"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT * FROM characters ORDER BY `player`") or die("SELECT Error: ".mysql_error()); $num = mysql_num_rows($result); if ($num > 0 ) { $i=0; while ($i < $num) { $character_name = mysql_result($result,$i,"character_name"); $breed = mysql_result($result,$i,"breed"); $gender = mysql_result($result,$i,"gender"); $base_color = mysql_result($result,$i,"base_color"); $markings = mysql_result($result,$i,"markings"); $genetics = mysql_result($result,$i,"genetics"); $sire = mysql_result($result,$i,"sire"); $dam = mysql_result($result,$i,"dam"); $other = mysql_result($result,$i,"other"); $player = mysql_result($result,$i,"player"); $id = mysql_result($result,$i,"id"); echo "<b>$player</b><br>Horse ID Number: $id - $character_name - $breed - $gender - $base_color - $markings - $genetics - $sire - $dam - $other<br><br>"; ++$i; } } There are no errors in my statement as it displays what it's wrote to display correctly. What my question is, how do I display all of the queries in one table based on the entries of one column? The best way for me to explain this is to demonstrate HOW I want the results to display on my website. I would like it to display like the following: PLAYER ONE - Character one, character information - Character two, character information PLAYER TWO - Character one, character information - Character two, character information So on and so forth. I only want the Players to display once, but I want all of the characters and character information with the same player to display underneath the player name. I've tried a million different ways, and I'm just too new to PHP and MySQL I guess to figure this out. Any help would be extremely helpful. Hopefully I got all of the information down from the rules.. Don't be too hard on the noob!
×
×
  • 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.