Jump to content

salto

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Posts posted by salto

  1. Good morning,

    I am a bit stuck on formating the following query.  The methods I have used in the past for getting results in tables werefor a single record return and don't seem to want to work.  Can anyone suggest the appropriate method or point me in a direction of what functions I should be looking at?

    Thanks for any insight!

    Cheers.
    Spence

    [code]
    <?php
    $link = mysql_connect('server', 'sitam', 'password');
    if (!$link) {
    die('Not connected : ' . mysql_error());
    }
    // select the environmental database
    $dbvariable = 'environmental';
    //  use dbvariable in case we need to use other db later.
    $db_selected = mysql_select_db($dbvariable, $link);
    if (!$db_selected) {
    die ('Can\'t connect to $dbvariable : ' . mysql_error());
    }
    $query = "SELECT * FROM res_v5 WHERE Canton LIKE '$canton_var' AND TIPO like '$landuse_var' AND Inunda LIKE '$proximity_var'";
    $result = mysql_query($query); 
    if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
    }
    if (mysql_num_rows($result) == 0) {
    echo "No rows found";
    exit;
    }
    $loop_num = 1;
    $space_val = "_";
    //this works, now testing foreach method
    while ($row = mysql_fetch_assoc($result)) {
    echo $loop_num;
    echo $row["ID"];
    echo $row["Canton"];
    echo $row["TIPO"];
    echo $row["Inunda"];
    echo $space_val;
    $loop_num = $loop_num + 1;
    }
    print ('did I make it here');
    ?>
    [/code]
  2. The output of the array is just the values I think and the html is added in by the tables tag in this part of the function.  The $query variable is the results of the array to my limited understanding.

    [code]echo "<table cellpadding=1 cellspacing=1 border=1>\n";
      echo "<tr><td>$key</td><td>$value</td></tr>\n";
    [/code]

    The post by ryanlwh is on to something although I haven't figured it out yet.  Creating a $CADASTRO_LINC variable from the initial query and using it again is exactly what I need to do.  I'm working on wrapping my head around ryanlwh's response... 

    Thanks again!
    Spencer
  3. [b]EDITED by ryanlwh: removed the connection info for security reason stated by Ken[/b]

    I am a relative newbie, so I apologize for my ignorance.  I am using the form handler below to query a single table and spit back a table of results.

    [code]<!-- Cedula Query Form Handler -->
    <?php
    $cedula2 = $_POST['cedula'];
    $canton2 = $_POST['canton'];
    $link = mysql_connect('****', '****', '****');
    if (!$link) {
      die('Not connected : ' . mysql_error());
    }

    // make canton2 the current db
    $db_selected = mysql_select_db($canton2, $link);
    if (!$db_selected) {
      die ('Can\'t connect to $canton2 : ' . mysql_error());
    }
    ?>
    <?php
    $query = mysql_fetch_array(mysql_query("SELECT * FROM informacion_registral WHERE CEDULA_PERSONAL LIKE '$cedula2'"), MYSQL_ASSOC);
    echo "<table cellpadding=1 cellspacing=1 border=1>\n";
    foreach ($query as $key => $value) {
      echo "<tr><td>$key</td><td>$value</td></tr>\n";
    }
    echo "</table>\n";
    ?>[/code]

    The table it spits out looks like this.  When I enter 105710879 as the Cedula in the first form.

    <!-- Cedula Query Form Handler -->
    <table cellpadding=1 cellspacing=1 border=1>
    <tr><td>ID</td><td>6</td></tr>
    <tr><td>REC_NO</td><td>6</td></tr>
    <tr><td>CATASTRO_LINC</td><td>64302</td></tr>
    <tr><td>PROPIETARIO</td><td>xxxxxxx</td></tr>
    <tr><td>CEDULA_PERSONAL</td><td>105710879</td></tr>
    <tr><td>FOLIO_REAL</td><td>230810</td></tr>
    <tr><td>PLANO_CATASTRO</td><td>xxxxxxx</td></tr>
    <tr><td>FECHA_INSCRIPCION</td><td>xxxxx</td></tr>
    <tr><td>AREA_REGISTRO</td><td>217.58</td></tr>
    <tr><td>NATURALEZA</td><td></td></tr>
    <tr><td>GRAVAMENES</td><td></td></tr>
    <tr><td>ANOTACIONES</td><td></td></tr>
    <tr><td>OBSERVACIONES</td><td> </td></tr>
    </table>

    What I would like to do is use the value for CATASTRO_LINC (in this case 64302) in another query.  Is there a call of some kind which will pull the catastrol_linc value out of that array and make it a variable so that I can use it to query a second related table and display its records as well?

    Ideally I would like to spit it back into another query and generate another table underneath.

    [code]
    ...
    <?php
    $query = mysql_fetch_array(mysql_query("SELECT * FROM TABLE2 WHERE CATASTRO_LINC LIKE '$the variable we created from the array'"), MYSQL_ASSOC);
    echo "<table cellpadding=1 cellspacing=1 border=1>\n";
    foreach ($query as $key => $value) {
      echo "<tr><td>$key</td><td>$value</td></tr>\n";
    }
    echo "</table>\n";
    ?>[/code]

    I hope this makes sense, and thank you for any insite on how to do this.

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