Jump to content

patchido

Members
  • Posts

    59
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

patchido's Achievements

Member

Member (2/5)

1

Reputation

  1. solved, the function sqlsrv_num_rows need this $params = array(); $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET ); $result = sqlsrv_query($conn, $tsql,$params,$options); from php.net Retrieves the number of rows in a result set. This function requires that the statment resource be created with a static or keyset cursor. For more information, see sqlsrv_query(), sqlsrv_prepare(), or ยป Specifying a Cursor Type and Selecting Rowsin the Microsoft SQLSRV documentation.
  2. Does asteriscs are for me not to reveal my info, the connection is successful, i get the right response but no rows
  3. so i am trying to connect to my sql through php. i am getting a connection, if i copy that query and place it over sql management studio i do get the results needed. what am i missing? I just get this on the response. Connection createdRows returned: <?php $serverName = "************"; $databaseName = "*********"; $connectionInfo = array("Database"=>"$databaseName", "UID"=>"*******","PWD"=>"*********"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ){ echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } else{ echo "Connection created"; } $tsql = "SELECT TOP 10 * FROM dbo.ActivityLog"; $result = sqlsrv_query($conn, $tsql); echo "Rows returned: ". sqlsrv_num_rows($result); sqlsrv_close($conn); ?>
  4. let me try that out, thats exactly what i wanted, (didn't know that existed) Thanks.
  5. the table won't show up in the forums :/ ill put part of it then. id username nombre ap_Paterno ap_Materno mail region_id localidad_id admin 2 Qualtia prueba prueba prueba prueba@qualtia.com 1 2 3 11 romtorre ROMELIA TORRES VELI romtorre@qualtia.com 1 4 2
  6. Hello, i have a table i have to fill out with info regarding other tables, is a join possible or do i have to make 2 queries? This is what i have right now. $date = date("Y-m-d H:i:s"); $sql = "INSERT INTO tblpaqueteria ( sender_id, reciever_id, AddTime, Estatus, ubicacion, tipo,slocalidad_id,rlocalidad_id ) VALUES ( '{$_POST['id_send']}', '{$_POST['id_rec']}', '{$date}', '0' , '0', '{$_POST['tipo_paq']}',0,0 )"; $res = mysql_query($sql,$this->conn); return $sql; What i need now is to change some of my insert into dynamic ones, i have to enter into "slocalidad_id" and into "ubicacion" the "id" of a table called localidad, and this id is being referenced from a table called "usuarios" (users) where "$_POST['id_send']" where localidad_id marks the id i need to insert into tblpaqueteria. I am not sure if I explained myself correctly so ill try and make an example. usuarios So for my sql above, without joins i would be receiving from POST id_send = 2 and from id_rec 11 so my query should insert this $sql = "INSERT INTO tblpaqueteria ( sender_id, reciever_id, AddTime, Estatus, ubicacion, tipo,slocalidad_id,rlocalidad_id ) VALUES ( '{$_POST['id_send']}', '{$_POST['id_rec']}', '{$date}', '0' , '2', '{$_POST['tipo_paq']}',2,4 )"; notice the numbers "2" and "4" being inserted, those are the ones i don't know how to enter dynamically, i think its a join, but i don't know how to use them in an insert. Thanks a lot
  7. solved it, this made the trick $ids = $_POST['ids']; $os = $_POST['os']; $i = 0; $sql = "UPDATE tblpaqueteria INNER JOIN guias ON (guias.id = tblpaqueteria.guia_id) SET tblpaqueteria.Estatus = 2, guias.guia = CASE tblpaqueteria.guia_id"; foreach ($os as $val) { $sql .= sprintf(" WHEN %u THEN %u ", intval($ids[$i]), intval($val)); $i++; } $sql .= "END WHERE tblpaqueteria.guia_id IN (" . implode(", ", array_map('intval', $ids)) . ")"; i used your example with the example barand made. Thanks a lot guys!
  8. so, this is what i ended up with your example. $ids = $_POST['ids']; $os = $_POST['os']; $i = 0; $sql = "UPDATE tblpaqueteria t INNER JOIN guias g ON (g.id = t.guia_id) SET t.Estatus = 2, g.guia = CASE "; foreach ($os as $val) { $sql .= sprintf("WHEN t.guia_id = %u THEN g.guia = %u ", intval($ids[$i]), intval($val)); $i++; } $sql .= "END WHERE t.guia_id IN (".implode(", ", array_map('intval', $ids)).")"; mysql_query($sql); return $sql; i got this query UPDATE tblpaqueteria t INNER JOIN guias g ON (g.id = t.guia_id) SET t.Estatus = 2, g.guia = CASE WHEN t.guia_id = 39 THEN g.guia = 50 WHEN t.guia_id = 40 THEN g.guia = 100 END WHERE t.guia_id IN (39, 40) and the table tblpaqueteria did update while the table guia didn't.
  9. a more ilustrative example, ill have a id array with this info [34,35,36] and an array $os with [134,145,256] i want to change tblpaqueteria.Estatus = 2 in all tblpaqueteria.guia_id matching 34 35 and 36, after that i want that in the guias.guia updates to 134 where guias.id = 34 and guias.guia updates to 145 where guias.id = 35 and guia.guias updates to 256 where guias.id = 36. THANSK
  10. the array "id" would also have more than 1 value, both arrays have the same length, and the indexes match for ex the id with index of 0 would have the "guia" in the "os" array with the index of 0 and ht indexed 1 would be indexed with the one of 1 too, i am not sure if i am being clear. Thanks.
  11. that worked! but sometimes ill get more than 1 value, how can i make that dynamic?
  12. it is always 2, $_POST['os'] is an array, i get an error becuase of that. <br /> <b>Warning</b>: mysql_real_escape_string() expects parameter 1 to be string, array given in <b>E:\xampplite\htdocs\Mensajeria\includes\registro.class.php</b> on line <b>184</b><br />
×
×
  • 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.