Jump to content


Photo

Ajuda Com Relação De Tabelas


  • Faça o login para participar
1 reply to this topic

#1 Azzurra.com

Azzurra.com

    Novato no fórum

  • Usuários
  • 1 posts
  • Sexo:Não informado

Posted 31/01/2009, 20:21

Olá,

Eu tenho o seguinte problema:

Tenho 2 tabelas num sistema de cadastro de clientes e seus respectivos eventos, como cada cliente pode ter mais de 1 evento eu gostaria de obter uma ajuda pois fiz as tabelas da seguinte maneira:


clientes (Com os campos id_cliente e cliente)

clientes_eventos (Com os campos de id_cliente, id_evento e outos do evento)

O cadastramento do cliente e feito anteriormente ao cadastro do evento e no cadastro do evento eu inclui um list menu com os nomes de todos os clientes para selecão na hora de cadastrar o evento, eu gostaria de alimentar o campo id_cliente na tabela clientes_eventos com o id_cliente q eh selecionado no list menu q vem dá tabela clientes, só q tenho encontrado diversos meios mas nenhum efetivo gostaria de uma ajuda se possivel para a resolução desse problema, segue aki meu codigo:


<?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 clientes_eventos (tel_fixo, cel_noivo, cel_noiva, email, mot_evento, `local`, local_igreja, hora, orca_dj, orca_som_festa, orca_som_igreja, luz_pista, luz_decor_festa, valor_luz_festa, luz_decor_igreja, valor_luz_igreja, tela_tipo, vj, taxa_via, outros, dj, iluminador, indicacao, cerimonial, tel_cerimonial, num_convidados, obs, data_1_contato, data_proposta, data_confirma, data_reuniao, hora_reuniao, resp_reuniao, ligar_data) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
					   GetSQLValueString($_POST['tel_fixo'], "text"),
					   GetSQLValueString($_POST['cel_noivo'], "text"),
					   GetSQLValueString($_POST['cel_noiva'], "text"),
					   GetSQLValueString($_POST['email'], "text"),
					   GetSQLValueString($_POST['mot_evento'], "text"),
					   GetSQLValueString($_POST['local'], "text"),
					   GetSQLValueString($_POST['local_igreja'], "text"),
					   GetSQLValueString($_POST['hora'], "date"),
					   GetSQLValueString($_POST['orca_dj'], "text"),
					   GetSQLValueString($_POST['orca_som_festa'], "text"),
					   GetSQLValueString($_POST['orca_som_igreja'], "text"),
					   GetSQLValueString($_POST['luz_pista'], "text"),
					   GetSQLValueString($_POST['luz_decor_festa'], "text"),
					   GetSQLValueString($_POST['valor_luz_festa'], "text"),
					   GetSQLValueString($_POST['luz_decor_igreja'], "text"),
					   GetSQLValueString($_POST['valor_luz_igreja'], "text"),
					   GetSQLValueString($_POST['tela_tipo'], "text"),
					   GetSQLValueString($_POST['vj'], "text"),
					   GetSQLValueString($_POST['taxa_via'], "text"),
					   GetSQLValueString($_POST['outros'], "text"),
					   GetSQLValueString($_POST['dj'], "text"),
					   GetSQLValueString($_POST['iluminador'], "text"),
					   GetSQLValueString($_POST['indicacao'], "text"),
					   GetSQLValueString($_POST['cerimonial'], "text"),
					   GetSQLValueString($_POST['tel_cerimonial'], "text"),
					   GetSQLValueString($_POST['num_convidados'], "int"),
					   GetSQLValueString($_POST['obs'], "text"),
					   GetSQLValueString($_POST['data_1_contato'], "date"),
					   GetSQLValueString($_POST['data_proposta'], "date"),
					   GetSQLValueString($_POST['data_confirma'], "date"),
					   GetSQLValueString($_POST['data_reuniao'], "date"),
					   GetSQLValueString($_POST['hora_reuniao'], "date"),
					   GetSQLValueString($_POST['resp_reuniao'], "text"),
					   GetSQLValueString($_POST['ligar_data'], "date"));

  mysql_select_db($database_conexao, $conexao);
  $Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());

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


mysql_select_db($database_conexao, $conexao);
$query_lista_clientes = "SELECT * FROM clientes";
$lista_clientes = mysql_query($query_lista_clientes, $conexao) or die(mysql_error());
$row_lista_clientes = mysql_fetch_assoc($lista_clientes);
$totalRows_lista_clientes = mysql_num_rows($lista_clientes);

mysql_select_db($database_conexao, $conexao);
$query_insert_evento = "SELECT id_cliente, tel_fixo, cel_noivo, cel_noiva, email, mot_evento, `local`, local_igreja, `data`, hora, orca_dj, orca_som_festa, orca_som_igreja, luz_pista, luz_decor_festa, valor_luz_festa, luz_decor_igreja, valor_luz_igreja, tela_tipo, vj, taxa_via, outros, dj, iluminador, indicacao, cerimonial, tel_cerimonial, num_convidados, obs, data_1_contato, data_proposta, data_confirma, data_reuniao, hora_reuniao, resp_reuniao, ligar_data, confirmado, n_confirmado, cerimonia_local, cortesia FROM clientes_eventos";
$insert_evento = mysql_query($query_insert_evento, $conexao) or die(mysql_error());
$row_insert_evento = mysql_fetch_assoc($insert_evento);
$totalRows_insert_evento = mysql_num_rows($insert_evento); 
?>

Ps.: sou iniciante em php/mysql aprendi(ou estou tentando) na marra entaum qq ajuda para modificações novas ideias serão bem aceitas!!!

Obrigado

#2 Squall Robert

Squall Robert

    Mr. Squall - Mais Carne do que Osso (hihi)

  • Usuários
  • 507 posts
  • Sexo:Masculino
  • Localidade:Curitiba
  • Interesses:Php ... Php...Php

Posted 04/02/2009, 15:36

NESTE CASO VC TEM QUE SAR INNER JOIN

select * from tabela 1 INNER JOIN tabela 2 on (tabela1.campo = tabela2.campo)
<?php

$squall = new Squall();

$squall->Ajudando("você");

$resultado = $squall->solucao();  ?>




0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq