Jump to content

php MySQL Result script


mike239

Recommended Posts

<?php require_once('Connections/circle.php'); ?>

<?php

if (!function_exists("PostSQLValueString")) {

function PostSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = post_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

 

$maxRows_ToolResults = 2;

$pageNum_ToolResults = 0;

if (isset($_POST['pageNum_ToolResults'])) {

  $pageNum_ToolResults = $_POST['pageNum_ToolResults'];

}

$startRow_ToolResults = $pageNum_ToolResults * $maxRows_ToolResults;

 

mysql_select_db($database_circle, $circle);

$query_ToolResults = "SELECT * FROM tooltable";

$query_limit_ToolResults = sprintf("%s LIMIT %d, %d", $query_ToolResults, $startRow_ToolResults, $maxRows_ToolResults);

$ToolResults = mysql_query($query_limit_ToolResults, $circle) or die(mysql_error());

$row_ToolResults = mysql_fetch_assoc($ToolResults);

 

if (isset($_POST['totalRows_ToolResults'])) {

  $totalRows_ToolResults = $_POST['totalRows_ToolResults'];

} else {

  $all_ToolResults = mysql_query($query_ToolResults);

  $totalRows_ToolResults = mysql_num_rows($all_ToolResults);

}

$totalPages_ToolResults = ceil($totalRows_ToolResults/$maxRows_ToolResults)-1;

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Circle Tool Results</title>

<style type="text/css">

<!--

body {

background-color: #00CCCC;

}

body,td,th {

color: #000000;

}

a:link {

color: #000000;

text-decoration: none;

}

a:visited {

text-decoration: none;

color: #000000;

}

a:hover {

text-decoration: none;

}

a:active {

text-decoration: none;

}

-->

</style></head>

 

<body>

<table border="1">

  <tr>

    <td>ToolNumber</td>

    <td>ToolLocation</td>

    <td>Quantity</td>

    <td>Owner</td>

    <td>Notes</td>

  </tr>

  <?php do { ?>

    <tr>

      <td><?php echo $row_ToolResults['ToolNumber']; ?></td>

      <td><?php echo $row_ToolResults['ToolLocation']; ?></td>

      <td><?php echo $row_ToolResults['Quantity']; ?></td>

      <td><?php echo $row_ToolResults['Owner']; ?></td>

      <td><?php echo $row_ToolResults['Notes']; ?></td>

    </tr>

    <?php } while ($row_ToolResults = mysql_fetch_assoc($ToolResults)); ?>

</table>

<p>

  <a href="/search.php">

  <label>  </label>

</a></p>

<table width="123" border="1">

  <tr>

    <td width="127"><a href="/search.php">SEARCH MORE</a> </td>

  </tr>

</table>

</body>

</html>

<?php

mysql_free_result($ToolResults);

 

?>

 

oh, its for posting

 

it goes in here

 

your code would look like this

 

<?php require_once('Connections/circle.php'); ?>
<?php
if (!function_exists("PostSQLValueString")) {
function PostSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = post_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_ToolResults = 2;
$pageNum_ToolResults = 0;
if (isset($_POST['pageNum_ToolResults'])) {
  $pageNum_ToolResults = $_POST['pageNum_ToolResults'];
}
$startRow_ToolResults = $pageNum_ToolResults * $maxRows_ToolResults;

mysql_select_db($database_circle, $circle);
$query_ToolResults = "SELECT * FROM tooltable";
$query_limit_ToolResults = sprintf("%s LIMIT %d, %d", $query_ToolResults, $startRow_ToolResults, $maxRows_ToolResults);
$ToolResults = mysql_query($query_limit_ToolResults, $circle) or die(mysql_error());
$row_ToolResults = mysql_fetch_assoc($ToolResults);

if (isset($_POST['totalRows_ToolResults'])) {
  $totalRows_ToolResults = $_POST['totalRows_ToolResults'];
} else {
  $all_ToolResults = mysql_query($query_ToolResults);
  $totalRows_ToolResults = mysql_num_rows($all_ToolResults);
}
$totalPages_ToolResults = ceil($totalRows_ToolResults/$maxRows_ToolResults)-1;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Circle Tool Results</title>
<style type="text/css">
<!--
body {
   background-color: #00CCCC;
}
body,td,th {
   color: #000000;
}
a:link {
   color: #000000;
   text-decoration: none;
}
a:visited {
   text-decoration: none;
   color: #000000;
}
a:hover {
   text-decoration: none;
}
a:active {
   text-decoration: none;
}
-->
</style></head>

<body>
<table border="1">
  <tr>
    <td>ToolNumber</td>
    <td>ToolLocation</td>
    <td>Quantity</td>
    <td>Owner</td>
    <td>Notes</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_ToolResults['ToolNumber']; ?></td>
      <td><?php echo $row_ToolResults['ToolLocation']; ?></td>
      <td><?php echo $row_ToolResults['Quantity']; ?></td>
      <td><?php echo $row_ToolResults['Owner']; ?></td>
      <td><?php echo $row_ToolResults['Notes']; ?></td>
    </tr>
    <?php } while ($row_ToolResults = mysql_fetch_assoc($ToolResults)); ?>
</table>
<p>
  <a href="/search.php">
  <label>  </label>
</a></p>
<table width="123" border="1">
  <tr>
    <td width="127"><a href="/search.php">SEARCH MORE</a> </td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($ToolResults);

?>

 

but its still the wrong code

Here is my search code--I thought since my results were displayed wrong it would have been in the result script-my bad still learning

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Tool Search</title>

<style type="text/css">

<!--

.style1 {

font-size: 36px;

font-weight: bold;

font-style: italic;

}

body {

background-color: #00CCFF;

}

body,td,th {

color: #FFFFFF;

}

-->

</style>

</head>

 

<body>

<div align="center" class="style1">CIRCLE TOOL SEARCH</div>

<form action="/results.php" method="get" name="form1" target="_parent" id="form1">

  <label>

  <input type="text" name="textfield" />

  </label>

  TYPE THE DESIRED TOOL NUMBER

  <label>

  <input type="submit" name="Submit" value="Submit" />

  </label>

</form>

</body>

</html>

 

Place you're code in here when posting 

That'll format it to:

Place you're code in here 

 

It's just easier for us to read your code with the syntax highlighting, and we don't have to scroll down the page.

 

 

As stated before, are you sure this is the search form code - not the actual form, but the code once you process it? In the code above, all I saw was

$query_ToolResults = "SELECT * FROM tooltable";

with no WHERE clause

Archived

This topic is now archived and is closed to further replies.

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