Jump to content

[SOLVED] Looping Result.. Why?


Andrius

Recommended Posts

Ok the URL to view the error is at : http://www.getlivemedia.com/Member_page.php

The Problem Code is below:
[code]<?

   
include("Includes/conn.php");

mysql_connect($host,$user,$password);

@mysql_select_db($database) or die("Unable to select database");

$query = " SELECT * FROM Featured , Streams ";

$result = mysql_query($query);

$num = mysql_numrows($result);



mysql_close();

$i = 0;

while($i < $num)
{

//Featured Table
$f_id        = mysql_result($result,$i,"f_id");
    $subject    = mysql_result($result,$i,"f_subject");
    $body        = mysql_result($result,$i,"f_body");
$cam_url    = mysql_result($result,$i,"f_cam_url");
$time        = mysql_result($result,$i,"f_time");
$image      = mysql_result($result,$i,"f_image");
$status      = mysql_result($result,$i,"f_status");
$url        = "Feed.php?id=$f_id";

//Streams Table
$s_id                = mysql_result($result,$a,"s_id");
    $s_user              = mysql_result($result,$a,"s_user");
    $s_cam_url            = mysql_result($result,$a,"s_cam_url");
$s_show_image        = mysql_result($result,$a,"s_show_image");
$s_show_name          = mysql_result($result,$a,"s_show_name");
$s_show_description  = mysql_result($result,$a,"s_show_description");
$s_show_status        = mysql_result($result,$a,"s_show_status");
$s_show_time          = mysql_result($result,$a,"s_show_time");
$s_button            = mysql_result($result,$a,"s_button");
$s_category          = mysql_result($result,$a,"s_category");

if ( $status == "1" )
      {
echo "
<table width='497' border='0' cellspacing='0' cellpadding='1'>
  <tr>
    <td bgcolor='#FFFFFF'><div align='center'>
      <table width='495' border='0' cellspacing='0' cellpadding='2'>
        <tr>
          <td width='99%' bgcolor='#191919'><div align='center'><img src='Feature_images/$image' width='300' height='200'/></div></td>
        </tr>
        <tr>
          <td height='20' bgcolor='#666666'><div align='center' class='style2'>$subject</div></td>
        </tr>
        <tr>
          <td height='20' valign='middle' bgcolor='#363636'><div align='center' class='style4'>$body   
          </div> </td>
          </tr>
        <tr>
          <td height='20' bgcolor='#666666'><div align='center'><span class='style2'>SHOW BEGINS AT: $time</span></div></td>
        </tr>
        <tr>
          <td height='20' valign='middle' bgcolor='#363636'><div align='center' class='style4'>PLEASE BE ADVISED THE SHOW IS LIMITED TO <span class='style2'>50</span> USERS PER FEED <br><br>
  <A HREF=\"http://www.getliveevents.com/$url\" onClick=\"return popup(this, 'notes')\"><img src='Images/btn_watch_live.jpg' border=0/></A>
           
          </div></td>
        </tr>
     
      </table>
    </div></td>
  </tr>
</table><br><Br>
";
} else {
echo "";
}
 
  $i++;
}

echo "<table width='702' border='0' cellspacing='0' cellpadding='1'>
    <tr>
      <td bgcolor='#FFFFFF'><div align='center'>
        <table width='700' border='0' cellpadding='2' cellspacing='2' bgcolor='#333333'>
          <tr>
            <td width='139' bgcolor='#970000' class='style4'><div align='center' class='style5'>CATEGORY</div></td>
            <td width='424' bgcolor='#970000' class='style4'><div align='center' class='style5'>SHOW NAME </div></td>
            <td width='127' bgcolor='#970000'><div align='center' class='style5'>SCHEDULE</div></td>
          </tr>";

$a = 1;

while($a < $num)
{
if ( $s_show_status == "1" )
      {
echo "
  <tr>
            <td bgcolor='#FF0000' class='style4'><div align='center'>$s_category</div></td>
            <td class='style4'><div align='left'>$s_show_name</div></td>
            <td class='style4'><div align='center'>$s_show_time</div></td>
          </tr>
       
";
} else {
echo "";
}
 
  $a++;
}
echo "</table>
      </div></td>
    </tr>
  </table>";

?>[/code]

Thanks sooo much for any help!
Link to comment
Share on other sites

the question is why is it looping the results.  is should be cycling through the results and displaying eg: show A... show B... show C but instead it's looping show A.

My second question is.. how can I modify this code to do the following:
I need this code to display all shows from the table Featured in 1 html table and I need all results from Streams to be displayed in a second HTML table that looks differant from the first completely. 

Cant wait to hear ideas.. thanks!!
Link to comment
Share on other sites

That code is terrible... in my opinion... very messy and hard to understand.

Instead of using mysql_result a bunch of times which retrieves 1 row, try this...

[code]while($row=mysql_fetch_assoc($result))
{

//Featured Table
$f_id = $row[f_id];
    $subject    = $row[f_subject];
    $body        = $row[f_body];
$cam_url    = $row[f_cam_url];
$time        = $row[f_time];
$image      = $row[f_image];
$status      = $row[f_status];
$url        = "Feed.php?id=$f_id";

//Streams Table
$s_id                = $row[s_id];
    $s_user              = $row[s_user];
    $s_cam_url            = $row[s_cam_url];
$s_show_image        = $row[s_show_image];
$s_show_name          = $row[s_show_name];
$s_show_description  = $row[s_show_description]);
$s_show_status        = $row[s_show_status");
$s_show_time          = $row[s_show_time];
$s_button            = $row[s_button];
$s_category          =$row[s_category];

if ( $status == "1" )
      {
echo "
<table width='497' border='0' cellspacing='0' cellpadding='1'>
  <tr>
    <td bgcolor='#FFFFFF'><div align='center'>
      <table width='495' border='0' cellspacing='0' cellpadding='2'>
        <tr>
          <td width='99%' bgcolor='#191919'><div align='center'><img src='Feature_images/$image' width='300' height='200'/></div></td>
        </tr>
        <tr>
          <td height='20' bgcolor='#666666'><div align='center' class='style2'>$subject</div></td>
        </tr>
        <tr>
          <td height='20' valign='middle' bgcolor='#363636'><div align='center' class='style4'>$body   
          </div> </td>
          </tr>
        <tr>
          <td height='20' bgcolor='#666666'><div align='center'><span class='style2'>SHOW BEGINS AT: $time</span></div></td>
        </tr>
        <tr>
          <td height='20' valign='middle' bgcolor='#363636'><div align='center' class='style4'>PLEASE BE ADVISED THE SHOW IS LIMITED TO <span class='style2'>50</span> USERS PER FEED <br><br>
  <A HREF=\"http://www.getliveevents.com/$url\" onClick=\"return popup(this, 'notes')\"><img src='Images/btn_watch_live.jpg' border=0/></A>
           
          </div></td>
        </tr>
     
      </table>
    </div></td>
  </tr>
</table><br><br>";
} else {
echo "";
} //end else
} //end while loop

[/code]


This will loop through the results as long as there are results to display. 

There are several other things that I would do with this code, but its not my code... so hope this helps.
Link to comment
Share on other sites

thanks soooo much for the improved code.  I'm still a lil new at this whole php / mysql thing so I'm learning as I go as you can tell.  The new code seems to loop like the old code did and return results that are the same.  www.getliveevents.com/Member_page.php to see what I mean. 
Link to comment
Share on other sites

[b]chronister[/b]: Instead of transferring each key/value pair manually, use extract:

[code=php:0]
<?php

// This would really be an array from MySQL...
$mysql_row = array(
first => 'John',
last => 'Doe',
street => '100 Main St.',
state => 'IL',
city => 'Chicago',
);

echo "first = $first<br>";
extract($mysql_row);
echo "first = $first<br>";

?>[/code]
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.