vet911 Posted November 4, 2010 Share Posted November 4, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/217783-im-having-trouble-echoing-year-in-my-script-listed-below-is-the-script-just/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2010 Share Posted November 4, 2010 From the 1st line of your code to the line with echo $year, there's no code setting $year to any value so it will be a little hard for it to display anything when echoed. Quote Link to comment https://forums.phpfreaks.com/topic/217783-im-having-trouble-echoing-year-in-my-script-listed-below-is-the-script-just/#findComment-1130412 Share on other sites More sharing options...
vet911 Posted November 4, 2010 Author Share Posted November 4, 2010 Thanks for the quick response. I thought I was getting the $year from the select statement, which would have it as one of the variables. Is this not possible? Quote Link to comment https://forums.phpfreaks.com/topic/217783-im-having-trouble-echoing-year-in-my-script-listed-below-is-the-script-just/#findComment-1130413 Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2010 Share Posted November 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217783-im-having-trouble-echoing-year-in-my-script-listed-below-is-the-script-just/#findComment-1130418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.