Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using a mobile template for a personal site and I'm using it because of the menu format. The source and demo can be found here http://mobifreaks.com/free-mobile-website-templates/galaxy-mobi/ and all I have done to it is strip some of the content out of the page.

The menu is a CSS menu that is using jquery. I am using PHP to interact with a MySQL database so it is necessary to for me to use a PHP page. If I just save the page as a PHP page it works fine but when I add any PHP code to the page(in the body) both menu items are displayed like a normal list of buttons instead of a dropdown menu.

I add the following PHP to a post-content div:

<?php
while($rows=mysql_fetch_array($result) or die(mysql_error())){
?>
<table align="center" border="4" cellspacing="2" cellpadding="3" width="100%">
<tr><td>Date</td><td>Cateogry</td><td colspan="4">Decription</td><td>Credit</td><td>Debit</td></tr>
<tr><td class="datetable"><? echo $rows['date']; ?></td><td class="category"><? echo $rows['category']; ?></td><td class="description" colspan="4"><? echo $rows['description']; ?></td><td class="amount"><? echo $rows['amount']; ?></td><td class="amount"><? echo $rows['amount']; ?></td></tr>
<tr><td colspan="2" align="center"><a href="#top">Back To Top</a></td></tr>
</table>
<br>

<?php
}
?>

I'm curious if there's any way around this. If you would like any of my code or any more clarification, I'm happy to provide it. Thanks for all of the help.

share|improve this question
    
why a separate table/header for every DB row? plus, your or die() is pointless. when there's no more results, you'll get a false which triggers the die, and you output a "no error occured" error message. –  Marc B Dec 3 '13 at 17:26
    
Show your actual RENDERED HTML output, not your PHP code, –  Diodeus Dec 3 '13 at 17:26
1  
You really should be using MySQLi or PDO_MySQL, but that's a different discussion. What happens if you replace your while loop with while(($rows = mysql_fetch_array($result)) !== false) {? I think the or die causes the script to stop running once there are no more rows. –  Kyle Dec 3 '13 at 17:27
add comment

1 Answer

up vote 0 down vote accepted

The or die statement in your while loop is causing your PHP code to stop executing when there are no longer any results left to retrieve. The or die statement executes whenever mysql_fetch_array returns false (the end of your data set).

If you replace it with while(($rows = mysql_fetch_array($result)) !== false) {, then your PHP code will continue to run and should allow everything to execute correctly.

I see you are using the mysql_* functions. Please note that these have been deprecated for quite some time. I would highly recommend you look into MySQLi or PDO MySQL.

share|improve this answer
    
Awesome! Thanks a ton! I recently became aware that mysql_* was deprecated but I just wanted to get this up and running quickly, I appreciate the suggestion! –  Tom Meismer Dec 3 '13 at 17:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.