Jump to content

mgonzalez

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mgonzalez's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. if at first you don't succeed, try again, jaja. i'm still working on this project, i have the latest version of the script that has been developed (i removed everything between {}) and i'll try to post my understanding of what is needed still. i'm no programmer, so please bear with me. <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("estudio", $con); $result = mysql_query("SELECT * FROM legis57pan WHERE id=13"); here the table name will be set by hand, it's only 12 tables i have, all with the same structure, so once the command works for one, it should work for all. but, the command is all geared to work for guy # 13. i would need the command to detect the number of guys (rows) in the table and do all the calculation for each one and then store/print the cumulative output. i'm thinking some sort of loop. something like - $coincidencia_referencias=0; $vectorTemporal = array(); for($i=1; $i<118; $i++){ $vectorTemporal[$i]=0; the size of this array depends once more on the size of the table, so it would be ideal if this part could also be included in the global loop. while($row = mysql_fetch_array($result)) echo $coincidencia_referencias ." numero de coincidencias <br>"; $result3 = mysql_query("SELECT * FROM legis57pan WHERE id=13"); $row = mysql_fetch_assoc($result3); $arregloDeComisiones = array_keys($row, '1'); //busca donde las comisiones son = 1, es decir a que comisiones pertenece print_r($arregloDeComisiones); echo "<br>"."<br>"; this is already automatized, it recognizes which columns have value 1 for guy #13.this would have to be looped also, so that each guy gets screened this way and his coincidences added in an array for each. foreach($arregloDeComisiones as $key => $value){ echo $value; echo "<br>"; $result4 = mysql_query("SELECT id FROM legis57pan WHERE $value=1"); here the coincidences are added in an array, this array would have to be generated for each individual guy. while($row = mysql_fetch_assoc($result4)) //sumar las coincidencias en orden for($i=0;$i<116;$i++){ echo $vectorTemporal[$i]; } this array and size would have to be looped as well. ?> that's that, the command detects the size of the table, then analyzes each row, and generates an array that sums coincidences and has the size of the table, the end product is a square table, with as many rows and columns as the original table has rows. oks, greetings to all, thanks, marcos
  2. hello everyone, my name is marcos gonzález. i'm an economist by trade, and it was the scope of data and operations that my thesis has required to handle that had me get help and have some friends help me by programming in php and sql. currently this command only lacks a loop, so that it is repeated automatically. i hope a loop can be integrated easily, that would complete the data analysis process, allow me to get over with the whole thesis thing, and really would be something huge, something that i would greatly appreciate. i'll explain as briefly as possible the objective of the operations, and give a sample of how the sql tables look like, then post the code. the end result i look after is a table that has as many columns and rows as the root table it comes from. each would have as many rows and columns as each of the 12 tables i have so far because it would print the coincidences in groups (committees) for each individual against any other individual and this operation for the whole table in a coordinated system. in which the program looks for the groups for which an individual has ones, then looks for those other individuals with ones in those same groups and adds a one to the coincidence vector (which starts with all zeros) in the position of that individual. i already have a command which looks for coincidences in the different groups and adds them (and divides them between the total for each individual) in a vector. if the command could detect the number of rows for each particular table and then carry out these operation as many times and store each set of results in a different vector then the end result would be achieved. <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("estudio", $con); $result = mysql_query("SELECT * FROM legis57pan WHERE id=13"); $comisiones_referencia=0; $vectorTemporal = array(); for($i=1; $i<118; $i++){ $vectorTemporal[$i]=0; } for($i=1; $i<118; $i++){ $vector[$i][$i]=0; //$vector[$i]=$vector[$i]/ $comisiones_referencia; //echo ($vector[$i] . "<Br>") ; } while($row = mysql_fetch_array($result)) { if($row['c8']=='1') { $result2 = mysql_query("SELECT id FROM legis57pan WHERE c8=1"); while($row2 = mysql_fetch_array($result2)) { //echo $row2['id']."<br>"; $comisiones_referencia++; } } } $traeIds = mysql_query("SELECT id FROM legis57pan"); echo $comisiones_referencia ." numero de coincidencias <br>"; $result3 = mysql_query("SELECT * FROM legis57pan WHERE id=13"); $row = mysql_fetch_assoc($result3); $arregloDeComisiones = array_keys($row, '1'); //busca donde las comisiones son = 1, es decir a que comisiones pertenece print_r($arregloDeComisiones); echo "<br>"."<br>"; foreach($arregloDeComisiones as $key => $value){ echo $value; echo "<br>"; $result4 = mysql_query("SELECT id FROM legis57pan WHERE $value=1"); while($row = mysql_fetch_assoc($result4)) //sumar las coincidencias en orden { foreach ($row as $key => $value) { echo $key." ".$value."<br>"; //echo "Current value of $key: $value.\n"."<br>"; $vectorTemporal[$value]++; //suma 1 en las posiciones de vector correspondientes al id donde c8=1 } } } $indice_coincidencias[0][0]=$vectorTemporal; foreach($vectorTemporal as $key => $value){ $a = gettype($comisiones_referencia); $value = $value/$comisiones_referencia; echo $value."<br>"; } ?> legis57pan is the name of the first table (there are 12 different tables) id is the identifier for each individual (it is for this index that the command should be looped) coincidencia_referencias is the vector of coincidences (there should be one for each id, the result would be a print, a matrix where the first column is the first id and goes at the left and the other ids go increasing to the right) 118 is the number of rows in this table ( all tables have a different number of rows, so the loop should detect this total and carry out the command that number of times) there are deactivated parts this script, those were the first tries and matter not oks, i hope i was somewhat clear, and not overly verborreic, thanks in advance, marcos
  3. as i've said in my introduction, i'm not a programmer, but an economist. i'm just thankful for forums like these, and for the time everyone puts in and the helping spirit there is. oks, marcos
  4. mgonzalez

    hi

    people, hello there. my name is marcos gonzález. i'm a trained economist, i got a major in political science as well. however, i'm still working on my thesis to get both degrees. and those thesis are what brought me over to programming, albeit from a peripheral perspective yet. my thesis involves an analysis of committees in the mexican lower chamber. there are 3 major parties here in mexico, and each party gets as many seats in every committee as to reflect the percentage of seats each party holds for the whole chamber (every committee is an harmonic reduction of the chamber). this is very straightforward and it is even drafted into the chamber regulations. the way each party leader handles the seats it is due in every committee isn't that straightforward, and it is there that i'm working. my idea is that party leaders carefully balance and observe which representative goes where. then, i've been using sql and php to handle some databases and perform operations on them. i haven't programmed really, but i've had to start thinking like a programmer, so my friends and i could go from my abstract idea and needs to specific commands that churn out the desired results. i'm like at 80% progress so far, i just need to place a loop on the command that's been developed so it runs automatically over the databases. i'm then going to post in the code section. thanks a lot to everyone for your time and helpfulness, thanks for a great forum, the best wishes for all, marcos
×
×
  • 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.