Jump to content

[SOLVED] 2 questions need help


Attila

Recommended Posts

Question 1:

 

I have been trying to get the PHP $Post to work on a single page and it is not working....I have Echo statements to see what part of the if I am in and I go from the if to the else but no data is being pulled out of the database.  I have added that code below.  What am I missing or doing wrong?

 

<?
// start the session 
session_start();
ob_start();
include ('includes/allfunctions.php');
header("Cache-control: private"); //IE 6 Fix 
?>
<title>DDO Items</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="CSS/style.css" rel="stylesheet" type="text/css">
<body>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
  <tr> 
    <? include ('includes/header.php');
?>
  </tr>
  <tr> 
    <td height="500" align="center" valign="top"><map name="WeaponsMap">
      <area shape="rect" coords="84,22,135,67" href="goggles.php" target="_self" alt="Goggles">
    </map>
    <table width="160" border="1" cellspacing="1" cellpadding="2">
      <tr>
        <td width="150"><img src="Pictures/EquipmentScreen.jpg" alt="DDO Items" width="348" height="251" border="0" usemap="#Weapons"></td>
        </tr>
      <tr>
        <td><div align="center">
          <p>Just click on an area above to search for that type of item. <span class="style1">**Note the second weapon slot is for shields.**. </span></p>
          </div></td>
        </tr>
	<tr>
        <td><div align="center">In the search box below you can search for specific named items or you can search for something like "potency, wounding, dagger, etc". </div></td>
        </tr>
      <tr>
  <td>
<?
     $top_form = "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">
     <table border=\"2\" cellpadding=\"2\" cellspacing=\"2\" bordercolor=\"#333333\" bgcolor=\"#CCCCCC\">
        <tr align=\"center\" valign=\"middle\">
          <td colspan=\"1\">";
   $bottom_form = "</td>
        </tr>
      <tr>
          <td>Enter your search word, name, or phrase</td>
          <td><input type=\"text\" value=\"{$_POST['search']}\"></td>
        </tr>
        <tr align=\"center\" valign=\"middle\">
          <td colspan=\"2\">
        <input type=\"hidden\" name=\"op\" value=\"ds\">
        <input type=\"submit\" name=\"Submit\" value=\"Search\"></td>
        </tr>
      </table>
     </form>";
     
if ($_POST['op'] != "ds") 
   { 
      echo "In the if";
      echo "$top_form"."$bottom_form";
   } 
   else
      {
         echo "in the else";
         $item = $_POST['search'];
         echo "$item";
	// $sql = 'SELECT * FROM `ddoitems` WHERE `ItemDescription` LIKE "%$item%"';
         $sql = 'SELECT * FROM `ddoitems` WHERE `ItemDescription` LIKE "%$item%"';
         database_connect();
         $result = mysql_query($sql/*, $dbconnection check php.net for the right syntax */) or die(mysql_error());
            while($row = mysql_fetch_array($result)) {
            echo '<tr>';
              echo '<td><div align="center" class="style1">'.$row['ItemName'].'</div></td>';
            echo '<td><div align="center" class="style1">'.$row['ItemDescription'].'</div></td>';
            echo '<td><div align="center" class="style1">'.$row['Type'].'</div></td>';
            echo '<td><div align="center" class="style1">'.$row['QuestName'].'</div></td>';
            echo '<td><div align="center" class="style1">'.$row['lvl'].'</div></td>';
            echo '<td><div align="center" class="style1">'.$row['Notes'].'</div></td>';
              echo '</tr>';

         }
      }
               
?>

</table>
    <p>I am still working on this page the search function is not operational yet. </p></td>
  </tr>
    <td align="center" valign="bottom"><? include ('includes/footer.php')?>
   </td>
</table>


<map name="Weapons">
  <area shape="rect" coords="287,187,338,232" href="rings.php" target="_self" alt="Rings">
  <area shape="rect" coords="287,133,338,178" href="belts.php" target="_self" alt="Belt">
  <area shape="rect" coords="287,75,338,120" href="cloak.php" target="_self" alt="Cloak">
  <area shape="rect" coords="287,20,338,65" href="trinkets.php" target="_self" alt="Trinkets">
  <area shape="rect" coords="216,202,267,247" href="gloves.php" target="_self" alt="Gloves">
  <area shape="rect" coords="148,202,199,247" href="boots.php" target="_self" alt="Boots">
  <area shape="rect" coords="216,8,267,53" href="necklace.php" target="_self" alt="Necklace">
  <area shape="rect" coords="147,7,198,52" href="helm.php" target="_self" alt="Helm">
  <area shape="rect" coords="84,188,135,233" href="rings.php" target="_self" alt="Rings">
  <area shape="rect" coords="84,131,135,176" href="gloves.php" target="_self" alt="Gloves">
  <area shape="rect" coords="83,76,134,121" href="armor.php" target="_self" alt="Armor">
  <area shape="rect" coords="8,53,60,93" href="weapons.php" target="_self" alt="Weapons">
<area shape="rect" coords="8,108,59,150" href="shields.php" target="_self" alt="Shields">
<area shape="rect" coords="8,167,59,209" href="arrows.php" target="_self" alt="Arrows / Bolts"><area shape="rect" coords="84,22,135,67" href="goggles.php" target="_self" alt="Goggles">
</map>
</html>

 

 

Question 2

What so I have to adjust on the following code to get it to display all the items it pulls out of the database in ascending alphetabical order by the ItemName?  Code provided below.

 

 

$sql = 'SELECT * FROM `ddoitems` WHERE `ItemType` LIKE \'%Cloak%\'';
database_connect();
$result = mysql_query($sql) or die(mysql_error());
   while($row = mysql_fetch_array($result)) {
		if ($row['hyperlink'] == NULL) 
			{ 
				echo '<tr>';
        			echo '<td><div align="center" class="style1">'.$row['ItemName'].'</div></td>';
				echo '<td><div align="center" class="style1">'.$row['ItemDescription'].'</div></td>';
				echo '<td><div align="center" class="style1">'.$row['Type'].'</div></td>';
				echo '<td><div align="center" class="style1">'.$row['QuestName'].'</div></td>';
				echo '<td><div align="center" class="style1">'.$row['lvl'].'</div></td>';
				echo '<td><div align="center" class="style1">'.$row['Notes'].'</div></td>';
        			echo '</tr>';
			} else {
						echo '<tr>';
			        	echo '<td><div align="center" class="style1"><a href="'.$row['hyperlink'].'"target="_blank">'.$row['ItemName'].'</a></div></td>';
           					echo '<td><div align="center" class="style1">'.$row['ItemDescription'].'</div></td>';
						echo '<td><div align="center" class="style1">'.$row['Type'].'</div></td>';
						echo '<td><div align="center" class="style1">'.$row['QuestName'].'</div></td>';
						echo '<td><div align="center" class="style1">'.$row['lvl'].'</div></td>';
						echo '<td><div align="center" class="style1">'.$row['Notes'].'</div></td>';
			        	echo '</tr>';
					}
}
?>	

 

Thanks for all your help.

Link to comment
Share on other sites

1.) Well, you've not given your textfield a name. I assume it was supposed to be called search? :

 

<input type=\"text\" value=\"{$_POST['search']}\" name="search" />

 

Without more info, that's about all i can suggest. What's the current output?

 

 

2.) Add an order by clause:

 

$sql = "SELECT * FROM `ddoitems` WHERE `ItemType` LIKE ''%Cloak%' ORDER BY ItemName ASC";

Link to comment
Share on other sites

OK thanks for the ascending thing that worked still having problems with the forum and grabbing data from the database.  Here is the coding again....I did do the name fix on the forum though.

 

$sql = 'SELECT * FROM `ddoitems` WHERE `ItemDescription` LIKE \'%$item%\'';

 

The $item is what I get from the form.  I know it is getting it's info because I can echo it back to me.  Just no mater how I put the $item I get an error.  I beleive my syntax is wrong can someone show me the propper syntax?

 

Thanks,

Link to comment
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.