Jump to content

Issue Looping through database items using for and while


HDFilmMaker2112

Recommended Posts

I'm having a bit of an issue with the below:

 

for($i=1; $i <= 3; $i++){
$credits_query="SELECT * FROM $tbl_name4 WHERE film_number='$i'";
$credits_result=mysql_query($credits_query);
$content.='
<div class="credit_header">';
if($i==1){$content.='First';}elseif($i==2){$content.='Second';}elseif($i==3){$content.='Third';} 
$content.=' Film Crew/Producer Credits
</div>
<table class="producer_table">
<tr class="producer_background">
<td class="border sixty">
Crew or Producer Position
</td>
<td class="border  twenty">
Amount
</td>
<td class="border">
Buy
</td>
</tr>
</table>
<div class="producer_scroll">
<table class="producer_table">';
while($credits_row=mysql_fetch_row($credits_result)){
extract($credits_row);
$content.='
<tr align="center">
<td class="border sixty">'
.$position.
'</td>
<td class="border twenty">$'
.$cost.
'</td>
<td class="border">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="'.$product_code.'">QMNXL6WXL4YL6
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</td>
</tr>';
}
$content.='
</table>
</div>';
}

 

I'm trying to make it loop three times, once for each film. Under each generated table it will be filled in with the credits available for purchase for that specific film, with that data being pulled from the database. Currently, it's not generating the tables with the database data:

 

It just does this:

<div class="producer_scroll">
<table class="producer_table">
</table>
</div>

 

 

<div class="credit_header">First Film Crew/Producer Credits
</div>
<table class="producer_table">
<tr class="producer_background">
<td class="border sixty">
Crew or Producer Position

</td>
<td class="border  twenty">
Amount
</td>
<td class="border">
Buy
</td>
</tr>
</table>
<div class="producer_scroll">
<table class="producer_table">
</table>
</div>
<div class="credit_header">Second Film Crew/Producer Credits
</div>
<table class="producer_table">
<tr class="producer_background">

<td class="border sixty">
Crew or Producer Position
</td>
<td class="border  twenty">
Amount
</td>
<td class="border">
Buy
</td>
</tr>
</table>
<div class="producer_scroll">
<table class="producer_table">
</table>
</div>
<div class="credit_header">Third Film Crew/Producer Credits
</div>

<table class="producer_table">
<tr class="producer_background">
<td class="border sixty">
Crew or Producer Position
</td>
<td class="border  twenty">
Amount
</td>
<td class="border">
Buy
</td>
</tr>
</table>
<div class="producer_scroll">
<table class="producer_table">
</table>
</div>

Link to comment
Share on other sites

Forgot to mention it also gives this error:

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/zyquo/public_html/makethemoviehappen.com/main.php on line 347

 

Line 347 -> while($credits_row=mysql_fetch_array($credits_result)){

 

EDIT: I didn't set the $tbl_name4 variable. All my problems are so simple...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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