Jump to content

I'm having trouble echoing $year in my script. Listed below is the script, just


vet911

Recommended Posts

I'm having trouble echoing $year in my script. Listed below is the script, just below ,$result = mysql_query("SELECT * FROM $dbname WHERE class LIKE '%$search%'") or die(mysql_error());, in the script I try to echo $year. It doesn't show up in the table on the webpage. Everything else works fine. Any help wold be appreciated greatly. Thanks in advance.

 

 

<?php
include 'config2.php';

$search=$_GET["search"];

// Connect to server and select database.
mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect");
mysql_select_db("vetman")or die("cannot select DB");


$result = mysql_query("SELECT * FROM $dbname WHERE class LIKE '%$search%'") or die(mysql_error());
// store the record of the "" table into $row
//$current = '';
echo "<table align=center border=1>";
echo "<br>";
echo "<tr>";
echo "<td align=center>";
?>
<div style="float: center;"><a><h1><?php echo $year; ?></h1></a></div>


<?php
echo "</td>";
echo "</tr>";
echo "</table>";


// keeps getting the next row until there are no more to get
if($result && mysql_num_rows($result) > 0)

{
    $i = 0;
    $max_columns = 2;
    echo "<table align=center>";
echo "<br>";
    while($row = mysql_fetch_array($result))
   {
       // make the variables easy to deal with
       extract($row);

       // open row if counter is zero
       if($i == 0)

          echo "<tr>";

          echo "<td align=center>";
          ?>
          <div style="float: left;">
          <div><img src="<?php echo $image1; ?>"></div>

	  </div>


          <?php
          echo "</td>";

       // increment counter - if counter = max columns, reset counter and close row
       if(++$i == $max_columns)
       {
           echo "</tr>";
           $i=0;
       }  // end if
   } // end while
} // end if results

// clean up table - makes your code valid!
if($i > 0)
{
    for($j=$i; $j<$max_columns;$j++)
        echo "<td> </td>";
   echo '</tr>';
}
mysql_close();
?>
</table>

Just about anything is possible in programming, as long as it makes logical sense.

 

You must fetch data from the result set of a query. In your code, that does not happen until later (after you are checking if the number of rows is greater than zero.) You would need to rearrange the logic so that your program accomplishes what you have stated you want it to do.

Archived

This topic is now archived and is closed to further replies.

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