Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Lucas-5281

Todos os resultados só abre se apertar no botão buscar

Recommended Posts

Bom dia amigos, estou começando mexer com php agora, e estou tendo muitos problemas, estou com um sistema de busca de usuários a busca esta funcionando perfeitamente, porem gostaria que assim que entrar na pagina todos os resultados aparecem de inicio, todos os resultados só esta aparecendo quando eu aperto no botão busca, se eu não apertar no botão buscar os resultados não aparecem de inicio. Teria como abrir todos os resultados assim que entra na página?

<?php require_once('Connections/config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO `1` (nome, validade, email, login) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['nome'], "text"),
                       GetSQLValueString($_POST['validade'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['login'], "text"));

  mysql_select_db($database_config, $config);
  $Result1 = mysql_query($insertSQL, $config) or die(mysql_error());

  $insertGoTo = "master.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$colname_Recordset1 = "-1";
if (isset($_POST['00000'])) {
  $colname_Recordset1 = $_POST['00000'];
}
mysql_select_db($database_config, $config);


$query_Recordset1 = "SELECT * FROM `1` WHERE nome LIKE '%$colname_Recordset1' OR validade LIKE '%$colname_Recordset1' OR email LIKE '%$colname_Recordset1' OR login LIKE '%$colname_Recordset1'";




$Recordset1 = mysql_query($query_Recordset1, $config) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #09C;
}
</style>
<form name="form1" method="post" action="" style="float:left; margin-top:40px; margin-left:35px;">
  <label for="00000"></label>
  <input type="text" name="00000" id="00000">
  <input type="submit" name="button" id="button" value="Enviar">
</form>




<table width="100%" border="0" cellpadding="2" cellspacing="8">
  <?php do { ?>
    <tr>
      <td width="14%" bgcolor="#ffc000">Nome: <?php echo $row_Recordset1['nome']; ?></td>
      <td width="22%" bgcolor="#92d050">Validade: <?php echo $row_Recordset1['validade']; ?></td>
      <td width="34%" bgcolor="#ffc000">E-mail: <?php echo $row_Recordset1['email']; ?></td>
      <td width="21%" bgcolor="#92d050">Login cs: <?php echo $row_Recordset1['login']; ?></td>
      <td width="9%" ><img src="img/editar.png" width="27" height="25" style="margin-right:10px;"><img src="img/apagar.png" width="24" height="25"></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<?php
mysql_free_result($Recordset1);
?> 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Presta atenção no código abaixo, estude.

if($_SERVER['REQUEST_METHOD']=='POST')
{

$colname_Recordset1 = "-1";
if (isset($_POST['00000'])) {
  $colname_Recordset1 = $_POST['00000'];
}
mysql_select_db($database_config, $config);
$query_Recordset1 = "SELECT * FROM `1` WHERE nome LIKE '%$colname_Recordset1' OR validade LIKE '%$colname_Recordset1' OR email LIKE '%$colname_Recordset1' OR login LIKE '%$colname_Recordset1'";
}else{
mysql_select_db($database_config, $config);
$query_Recordset1 = "SELECT * FROM `1` WHERE nome";
}

Basta fazer uma verificação inicial, para "dizer" ao PHP para que ele execute a busca direto caso a requsição não venha por meio do formualário.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.