IQStudio
01-23-2005, 02:46 PM
I was curious if there was somebody out there that wouldn't mind taking a look at this and letting me know whats wrong with it. Heres the deal, its located at http://www.cocoaplex.com/movies.php The movies are taken from a mysql database and put into these tables. The problem occurs only when there is an odd number of movies in the top half of the table. (it is like that now) The problem is that the top right cell of the coming soon table is blank whenever there is an odd number of movies above. Please let me know if anyone can figure out what is wrong with my code, becuase i've been over it a thousand times and can't figure it out. I have attached the source code...
Edit: Removed attachment due to user/password
Craig Edwards
01-23-2005, 06:10 PM
Hi, I'm not too sure if this will work (can't really test it...), but I had a quick look through your code this pops out....
Where you output the films comming soon, you have...
........
if($row2["comingsoon"] == "1"){
if($row2["title"] != "\n"){
.........
Did you mean to have this instead (which falls in line with the rest of your code)?
........
if($row2["comingsoon"] == "1"){
if($row2["title"] != ""){
.........
Some casual observations on your code, your database queries seem to be a little wack... how you use the ALTER TABLE command seems out of context, and in fact unnessary (it has been a while since I've done any php/mysql so maybe I'm out of touch?). You appear to use it to order the results of your query, when in fact you can do that with SELECT (and should afaik).... e.g. "SELECT * FROM movies ORDER BY comingsoon" ...
IQStudio
01-23-2005, 08:18 PM
I have made the change you suggested, and actually removed the alter statements as you are correct, they served no purpose. I am still having the problem however.
IQStudio
01-23-2005, 08:24 PM
Forgot to attach the source code.... here it is
Craig Edwards
01-23-2005, 10:02 PM
I'm not sure what the problem is, but it (obviously?) is a problem with how you are displaying your results. Might I suggest you change how you display you results? You do infact duplicate a lot of code which is always a no-no, and 9/10 gives you werid bugs..... and most of the time its just easier to rewrite the relevant code...
Also, your two mysql quries for the current movies, and coming soon movies are exactly the same!? That seems pointless, espically when you filter the results by looking at the values of certain fields.. you do know you can get MySQL to only give you results that match a specifc condition (like in you if() statements)?
SELECT * FROM table WHERE field = value
Below is some (untested) code which could be an alternative to how you display your results, and should eliminate all that nasty code duplication (if you put the relevant code into its own function)...
// Query the database, we only want the movies that are coming soon...
$sql = "SELECT * FROM movies WHERE comingsoon = 1";
$result = mysql_query($sql, $conn);
// How many result per table row?
$noOfResultsPerRow = 2;
// We have result to print.
$resultsToPrint = true;
// While we have result to print, print them!
while($resultsToPrint)
{
// Start table row.
print("<tr>");
// Print a table column (result)
for($j = 0; $j != $noOfResultPerRow; $j++)
{
// Fetch a row, if there are no more results, stop.
if(!($row = mysql_fetch_array($result)))
{
// There are no more result to print, stop the while() loop on next iteration.
$resultsToPrint = false;
// Break out of the for() loop.
break;
}
// Fetched a row from the database, print results
print <<<HERE
<td width="300" align="center">
<br>
<span class="movietitles">$row[title]</span><br><br>
<img border=0 width=96 height=140 src=$row[picture]><br>
<span class="normaltext">Opens $row[opens] </span><br>
</td>
HERE;
}
// End table row.
print("</tr>");
}
Sorry I dont have a fix for your current code, but I hope this helps. If you have any questions about the code above, fire away!
IQStudio
01-26-2005, 12:06 AM
I don't think I quite understand what you mean. I'm not very good with php and mysql (obviously). Is there anybody who could explain a little more simply? or be able to rework the code for me?