Jump to content

Recommended Posts

I am working on a web site where the client wants people to be able to make queries on various coins, but wants them to stay on the same page. For example, he wants them to be able to query the entire inventory by pressing a button; but also be able to select certain categories and display them on the same page. I am relatively new with SQL and PHP; I have tested the queries out, and they all work, but all open up into a different page.

 

Here is a sample of the code

 

<form id="ah"  method="post" action="'allhalvesquery.php . $_SERVER['PHP_SELF'] . '">

</form>

<form id="fh"  method="post" action="'fhq.php . $_SERVER['PHP_SELF'] . '">

</form>

</div><!-- end of content -->

<div id="sidebar">

<h3>CATEGORIES</h3>

<input type="image" src="images/allhalves.jpg" alt="SUBMIT" onclick="ah.submit();" />

<input type="image" src="images/flowinghairhalves.jpg" alt="SUBMIT" onclick="fh.submit();" />

 

Here is the link to the test site so you can see how the queries work.....the "All Halves" query actually works, but can't get the others to work.

 

So, post what code that you have.  Yes, you can make it work all on one page, but we cannot point you in the right direction, if we don't see what you already have.

 

Make sure you wrap your code in the code blocks, its the # button.

Cheers, JC

Here is the main code, left out the head and all that jazz:

 

<div id="main">

<div id="content">

<p class="text">7 Day no questions asked full money back return policy on all purchases. </p>

<p class="text">All outbound shipping is FREE. Buyer pays return shipping. </p>

<p class="text">The item shown is the exact item you will receive.</p>

<p class="text">Thank You</p>

<form id="ah"  method="post" action="'allhalvesquery.php . $_SERVER['PHP_SELF'] . '">

</form>

<form id="fh"  method="post" action="'fhq.php . $_SERVER['PHP_SELF'] . '">

</form>

</div><!-- end of content -->

<div id="sidebar">

<h3>CATEGORIES</h3>

<input type="image" src="images/allhalves.jpg" alt="SUBMIT" onclick="ah.submit();" />

<input type="image" src="images/flowinghairhalves.jpg" alt="SUBMIT" onclick="fh.submit();" />

 

 

<form id="drapedbusthalves" name="drapedbusthalves" method="post" action="drapedbustquery.php">

  <input type="image" src="images/Draped-Bust-Halves.jpg" alt="SUBMIT" width="330" height="22" />

</form>

 

<form id="cappedbusthalves" name="cappedbusthalves" method="post" action="cappedbustquery.php">

  <input type="image" src="images/Capped-Bust-Halves.jpg" alt="SUBMIT" width="330" height="22" />

</form>

 

<form id="liberttseatedhalves" name="liberttseatedhalves" method="post" action="lsq.php">

  <input type="image" src="images/Liberty-Seated-Halves.jpg" alt="SUBMIT" width="330" height="22" />

</form>

 

<form id="barberhalves" name="barberhalves" method="post" action="barberhalvesquery.php">

  <input type="image" src="images/Barber-Halves.jpg" alt="SUBMIT" width="330" height="22" />

</form>

 

<form id="silvercommemoratives" name="silvercommemoratives" method="post" action="silvercomquery.php">

  <input type="image" src="images/Silver-Commemoratives.jpg" alt="SUBMIT" width="330" height="22" />

</form>

 

<form id="walkinglibertyhalves" name="walkinglibertyhalves" method="post" action="walkingquery.php">

  <input type="image" src="images/Walking-Liberty-Halves.jpg" alt="SUBMIT" width="330" height="22" />

</form>

 

<div id="info">

    <p>*To avoid common dates Silverhalves.com only trades within the date ranges indicated.</p>

    </div><!-- end of info -->

</div><!-- end of sidebar -->

</div><!-- end of main -->

</div>

 

<!-- end of wrapper -->

<p class=kra><a href="http://krawebdesign.com/" target="_blank">Web Site by KRA Web Design</a></p>

</body>

</html>

 

This is the php of the query I am trying to submit - it works, just not displaying on the same page, going to a different page.

 

<?php

$dbc = mysql_connect('homesaleacrescom.ipagemysql.com', 'xxxx', 'xxxxx');

if (!$dbc) {

    die('Could not connect: ' . mysql_error());

}

 

mysql_select_db('coins', $dbc);

 

        $query = ("SELECT * FROM listings " );

 

$result = mysql_query($query);

 

echo "<table border='1'>

  <tr>

  <th>Coin ID</th>

  <th>Grading Service</th>

  <th>Mint Code</th>

  <th>Issue Date</th>

  <th>Title</th>

  <th>Grading Service</th>

  <th>Price</th>

  </tr>";

 

while($row = mysql_fetch_array($result)){

  echo "<tr>";

  echo "<td>" . $row['coinid'] . "</td>";

  echo "<td>" . $row['grading_service'] . "</td>";

  echo "<td>". $row['mint']."</td>";

  echo "<td>" . $row['issue_date']  . "</td>";

  echo "<td>" . $row['title'] . "</td>";

echo "<td>" . $row['grade'] . "</td>";

echo "<td>" . $row['price'] . "</td>";

  echo "</tr>";

  }

  echo "</table>";

 

if (!mysql_query($query,$dbc))

  {

  die('Error: ' . mysql_error());

  }

 

mysql_close($dbc);

?>

  • 2 weeks later...

What you need to do is take the WHERE clause out of all of your queries.  drapedbustquery.php through walkingquery.php has queries in them, look for the where clause in each files query.

Add a hidden field to each form (this is because IE doesn't pass name attributes with image inputs, IIRC), and make sure they are all the same name (type).  Notice the empty action attribute.

<form id="drapedbusthalves" name="drapedbusthalves" method="post" action="">
  <input type="hidden" name="type" value="drapedbusthalves" />
  <input type="image" src="images/Draped-Bust-Halves.jpg" alt="SUBMIT" width="330" height="22" />
</form>

Then make you a switch statement, and check for the type index in your post query.

<?php
$where = NULL; //where is built but is empty (NULL).
if(!empty($_POST['type'])) { //if the form is sent with the right named input.
$where = 'WHERE '; //where starts to build the WHERE clause.
switch($_POST['type']) { //switch the variable depending on the case.
  case: 'drapedbusthalves'; //if this is the contents of the type input element.
    $where .= ''; //this is where you put the "WHERE" clause from the corresponding drapedbustquery.php
    break; //dont' forget to end the switch here.
  case: 'cappedbusthalves'; //else if this is the contents of the input element "type".
    $where .= ''; //this is where you put the "WHERE" clause from the corresponding cappedbustquery.php
    break; //always break the switch at the end of case arguments for this switch (there are reasons not to do this, but in this switch you will need to).
  //etc... //continue until all cases are made.
}
}

 

Then you need to add one more thing.  The where clause to the query.

<?php
$query = ("SELECT * FROM listings $where" ); //add the where clause we built with the switch to the query.  This will be empty (showing a full page) if no button is pushed.

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.